Skip to content

Instantly share code, notes, and snippets.

@si14
Last active August 2, 2016 13:36
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 si14/9cf2c9f75048124989cdfd9ef5272169 to your computer and use it in GitHub Desktop.
Save si14/9cf2c9f75048124989cdfd9ef5272169 to your computer and use it in GitHub Desktop.
(let [m (into (sorted-map-by :idx)
{1834 {:id 1834, :idx 0}} )]
(prn (get m 1834 :test.some/guard))) ;; -> :test.some/guard, no errors
(let [m {1834 {:id 1834, :idx 0}}]
(prn (get m 1834 :test.some/guard2))) ;; -> found
(let [m (into (sorted-map-by #(compare (:idx %1) (:idx %2)))
{1834 {:id 1834, :idx 0}})]
(prn (get m 1834 :test.some/guard3))) ;; -> found
@si14
Copy link
Author

si14 commented Aug 2, 2016

apparently you can provide any function as a comparator in CLJS. If you screw up and provide e.g. keyword as a comparator, the map will be displayed properly, but all attempts to get an element from it will fail

Clojure handles this properly: ClassCastException clojure.lang.Keyword cannot be cast to java.util.Comparator clojure.core/sorted-map-by

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