Skip to content

Instantly share code, notes, and snippets.

@teaforthecat
Created January 15, 2019 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teaforthecat/d62e77063b8709fca71e56a7ce40bb3a to your computer and use it in GitHub Desktop.
Save teaforthecat/d62e77063b8709fca71e56a7ce40bb3a to your computer and use it in GitHub Desktop.
clojure state machine
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