-
-
Save cemerick/2f6cb5c287bd15d3bd79 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
; sorting seqables by length, but keep same-length seqables based on (in)equality | |
user=> (def comparator (reify java.util.Comparator | |
(compare [this x y] | |
(let [v (compare (count x) (count y))] | |
(if (and (zero? v) (not= x y)) | |
-1 | |
v))))) | |
#'user/comparator | |
user=> (sorted-set-by comparator "foo" "bar" "a" "b" "bar" "futz") | |
#{"b" | |
"a" | |
"bar" | |
"foo" "futz"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment