Created
May 2, 2012 14:03
-
-
Save ckirkendall/2576740 to your computer and use it in GitHub Desktop.
multimethods clojure
This file contains 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
;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