This is just a little note about one of my favorite datatypes in Clojure.
Like most Lisps, Clojure has a very useful group of datatypes built in including some
set types. I use
sorted-set a lot. Until recently, I hadn’t noticed
sorted-set-by, a function that returns a sorted set using a comparator you specify. I found myself needing to create a sorted set of strings where the sorting was case-insensitive. The
sorted-set-by function was exactly what I needed.
Here’s an example of usage.
case-insensitive-comparator function is probably a bit of over-engineering. Since this comparator just calls the built-in Java comparator, I could have used the
.compareToIgnorecase function more directly.