Simple variations on state machines in Clojure
Given a transition function that takes the current state and an input value as arguments then (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)) ;then each time you get an input-value: (send agt transition-fn input-value)
If you add a watch to the agent, you can react to state transitions.
I like it!
Alan
IWIN 68 2025 ra mắt, tặng code 99K tại iwin68-club.net! Thử bầu cua, xóc đĩa, tài xỉu… và thắng lớn ngay hôm nay!
Max88 là một trong những nhà cái trực tuyến nổi bật và được yêu thích tại châu Á. Với sự phát triển không ngừng và sự đổi mới trong dịch vụ, Max 88 đang khẳng định được vị thế của mình trong ngành cá cược trực tuyến.