automat
automat copied to clipboard
Shortcuts for choosing specific outputs
Per @moshez's suggestion:
The collector
callable passed to upon
runs on a generator of outputs. That means replacing it with next
, as suggested by the docs, for a transition that includes multiple outputs will result in only the first output running!
Often times you just want the last output's result. By adding a choose
argument to upon
, a user can use a numeric index to extract their desired output. For example, this:
someState.upon(someInput,
enter=anotherState,
outputs=[firstOutput, secondOutput],
choose=-1)
...would mean that someMachine.someInput()
would run both firstOutput
and secondOutput
, but only return secondOutput
's result.
What about choosing a specific output instead? Like so:
someState.upon(someInput,
enter=anotherState,
outputs=[firstOutput, secondOutput],
choose=secondOutput)
Is that too verbose?