Created
January 15, 2019 19:35
-
-
Save teaforthecat/d62e77063b8709fca71e56a7ce40bb3a to your computer and use it in GitHub Desktop.
clojure state machine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
state (atom :continue) | |
;; state event new state | |
state-machine {:continue {:pause :paused | |
:halt :halting} | |
:paused {:resume :resuming | |
:halt :halting} | |
:resuming {:continue :continue} | |
:halting {:halt :halted}} | |
step-state (fn [transition] | |
(swap! state #(get-in state-machine [% transition]))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment