Skip to content

Instantly share code, notes, and snippets.

@ckirkendall
Created May 2, 2012 14:03
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 ckirkendall/2576740 to your computer and use it in GitHub Desktop.
Save ckirkendall/2576740 to your computer and use it in GitHub Desktop.
multimethods clojure
;you have a map with a key :action
;this contains a known list of actions:
;:login, :register, :play, :logout
(defmulti appy-action :action)
;input looks like this
;{:action :login :username "test" :password "test"}
(defmethod apply-action :login [msg]
(let [username (:username msg)
password (:password msg)]
...))
(defmethod apply-action :logout [msg]
(let [username (:username msg)]
...))
(defmethod apply-action :play [msg]
(let [move (:move msg)]
...))
(defmethod appply-action :register [msg]
(let [username (:username msg)
password (:password msg)]
...))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment