StateMachine.Guard (state_machine v0.1.6)

Guards are functions that help to decide whether it's allowed to proceed with Event or Transition. They might serve different purposes:

  • Preventing a state machine from getting into a state unless some criteria met
  • Creating event with multiple target states with a single source state

Guards should not have any side-effects, cause they are getting run no matter if transition is successful or not, and also to determine the list of possible events for a certain state.

Link to this section Summary

Functions

Check runs guards associated with given Event or Transition and returns true if all passed. First argument of the guard is a model, second argument is the context.

Unifies if and unless guards into a single stream of guards.

Link to this section Types

Specs

t(model) :: %StateMachine.Guard{
  arity: integer(),
  fun:
    (model, StateMachine.Context.t(model) -> boolean())
    | (model -> boolean())
    | (() -> boolean()),
  inverted: boolean()
}

Link to this section Functions

Link to this function

check(ctx, map)

Specs

Check runs guards associated with given Event or Transition and returns true if all passed. First argument of the guard is a model, second argument is the context.

Specs

prepare(keyword()) :: [t(any())]

Unifies if and unless guards into a single stream of guards.