Skip to content

Instantly share code, notes, and snippets.

@pjstadig
Created July 9, 2015 15:07
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 pjstadig/3215c5febf4861341c05 to your computer and use it in GitHub Desktop.
Save pjstadig/3215c5febf4861341c05 to your computer and use it in GitHub Desktop.
MultiFn does not implement java.util.Comparator
Clojure 1.6.0
user=> (defmulti cmp (fn [a b] [(class a) (class b)]))
#'user/cmp
user=> (defmethod cmp :default [a b] (compare a b))
#<MultiFn clojure.lang.MultiFn@1da5688d>
user=> (sort cmp [:b :a])
ClassCastException clojure.lang.MultiFn cannot be cast to java.util.Comparator clojure.core/sort (core.clj:2829)
user=> (sort (fn [a b] (cmp a b)) [:b :a])
(:a :b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment