Skip to content

Instantly share code, notes, and snippets.

@ihercowitz
Created June 3, 2013 11:29
Show Gist options
  • Save ihercowitz/5697557 to your computer and use it in GitHub Desktop.
Save ihercowitz/5697557 to your computer and use it in GitHub Desktop.
Clojure - Multimethod with multi parameters
(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"))
@ihercowitz
Copy link
Author

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment