Last Updated: February 25, 2016
·
3.256K
· mishadoff

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)