Skip to content

Instantly share code, notes, and snippets.

@alexhall
Created October 16, 2012 14:54
Show Gist options
  • Save alexhall/3899779 to your computer and use it in GitHub Desktop.
Save alexhall/3899779 to your computer and use it in GitHub Desktop.
Multimethod prefer-method use
user> (defmulti m type)
#'user/m
user> (defmethod m Comparable [_] "comparable")
#<MultiFn clojure.lang.MultiFn@49c1e1e7>
user> (defmethod m Number [_] "number")
#<MultiFn clojure.lang.MultiFn@49c1e1e7>
user> (m "a")
"comparable"
user> (m 7)
; Evaluation aborted (exception complaining about conflicting matches for Number and Comparable)
user> (prefer-method m Number Comparable)
#<MultiFn clojure.lang.MultiFn@49c1e1e7>
user> (m 7)
"number"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment