-
-
Save si14/9cf2c9f75048124989cdfd9ef5272169 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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