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
t(model)
Specs
Link to this section Functions
check(ctx, map)
Specs
check( StateMachine.Context.t(m), StateMachine.Event.t(m) | StateMachine.Transition.t(m) ) :: boolean()
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.
prepare(opts)
Specs
Unifies if
and unless
guards into a single stream of guards.