Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hiredman
Created October 16, 2009 09:38
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 hiredman/211677 to your computer and use it in GitHub Desktop.
Save hiredman/211677 to your computer and use it in GitHub Desktop.
(def base-car #{:four-wheels})
(defmulti what-is-this identity)
(defmethod what-is-this #{:four-wheels} [_] (println "this is a base car"))
(defmethod what-is-this #{:four-wheels :mine} [_] (println "this is a base car of mine"))
(defmethod what-is-this #{:four-wheels :v8} [_] (println "this is a big car"))
(defmethod what-is-this #{:four-wheels :v8 :mine} [_] (println "this is a big car of mine"))
(defmethod what-is-this :default [_] (println "this is not a car"))
user=> (what-is-this base-car)
this is a base car
nil
user=> (conj base-car :mine)
#{:four-wheels :mine}
user=> (what-is-this *1)
this is a base car of mine
nil
user=> (conj base-car :suprise-tractor-hitch)
#{:four-wheels :suprise-tractor-hitch}
user=> (what-is-this *1)
this is not a car
nil
user=>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment