state_machine v0.1.1 StateMachine.Guard

Guards are functions bound to Events and Transitions that help to decide whether it's allowed to proceed. They might serve different purposes:

  • Protecting state maching from getting into some state unless some criteria met
  • Creating event with multiple target states

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, guard returning. Second argument is the context, that gets passed on to each guard.

Link to this section Types

Link to this type

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

Link to this section Functions

Check runs guards associated with given Event or Transition and returns true if all passed, guard returning. Second argument is the context, that gets passed on to each guard.

Link to this function

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