Skip to content

Instantly share code, notes, and snippets.

@kyleburton
Created November 16, 2011 03:29
Show Gist options
  • Save kyleburton/1369162 to your computer and use it in GitHub Desktop.
Save kyleburton/1369162 to your computer and use it in GitHub Desktop.
clojure multi-method dyn dispatch example
(defmulti my-multi (fn [arg]
(if (.startsWith arg "a")
:a
:b)))
(defmethod my-multi :a [arg]
(format "this is :a gonka-donk: %s" arg))
(defmethod my-multi :b [arg]
(format "b is the b is the b damn it: %s" arg))
(my-multi "foo") ;; => "b is the b is the b damn it: foo"
(my-multi "akerman") ;; => "this is :a gonka-donk: akerman"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment