(reduce transition-fn initial-state input)
returns the final state.If you are interested in intermediate states, you can use clojure.contrib.seq-utils/reductions instead of reduce.
If you want an asynchronous state machine, you can use an agent:
(def agt (agent initial-state))If you add a watch to the agent, you can react to state transitions.
;then each time you get an input-value:
(send agt transition-fn input-value)
No comments:
Post a Comment