Created
June 3, 2013 11:29
-
-
Save ihercowitz/5697557 to your computer and use it in GitHub Desktop.
Clojure - Multimethod with multi parameters
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
(defmulti action (fn [x] [(x :func) (x :speed)])) | |
(defmethod action [:run :fast] [x] (str "Running fast")) | |
(defmethod action [:run :slow] [x] (str "Running slow")) | |
(defmethod action :default [x] (str "Dont know what to do")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
user=> (action {:func :run :speed :fast})
"Running fast"
user=> (action {:func :run :speed :medium})
"Dont know what to do"
user=> (action {:func :run :speed :slow})
"Running slow"
user=> (action {:func :walk:speed :fast})
"Dont know what to do"