In Clojure, how do I sort a set of maps by a key within a value? -


this awkward question phrase, have set of maps so:

(def person-1 {:name "joshua" :birthday {:day 5 :month 12 :year 1960}}) (def person-2 {:name "louise" :birthday {:day 17 :month 4 :year 1987}}) (def person-3 {:name "jessica" :birthday {:day 28 :month 5 :year 1972}})  (def people #{person-1 person-2 person-3}) 

how sort people birth month, example?

i know (sort-by :name people) if wanted sort name, i'm not sure, syntactically, how example above work.

try:

(sort-by (comp :year :birthday) people) 

this sorts on person's year of birth.


comp takes list of functions , composes them single function first takes parameter, runs function on right first, takes result , proceeds leftward.

see comp in clojuredocs details.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -