Sorting by two fields in Clojure
Assuming you have a data represented by a vector of maps:
(def data [{:lastname "Brown" :firstname "John"}
{:lastname "Brown" :firstname "Jack"}
{:lastname "Apple" :firstname "Bruce"}
{:lastname "Crown" :firstname "King"}])
To sort it by :lastname and then by :firstname you can use awesome clojure snippet:
(sort-by (juxt :lastname :firstname) data)
Written by Mykhailo Kozik
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Clojure
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#