Skip to content

Instantly share code, notes, and snippets.

@cemerick
Created June 9, 2010 22:01
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 cemerick/2f6cb5c287bd15d3bd79 to your computer and use it in GitHub Desktop.
Save cemerick/2f6cb5c287bd15d3bd79 to your computer and use it in GitHub Desktop.
; 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