Programming-Idioms

History of Idiom 28 > diff from v43 to v44

Edit summary for version 44 :
[Clojure] No need for sample values

Version 43

Version 44

Idiom #28 Sort by a property

Sort elements of array-like collection items in ascending order of x.p, where p is a field of the type Item of the objects in items.

Idiom #28 Sort by a property

Sort elements of array-like collection items in ascending order of x.p, where p is a field of the type Item of the objects in items.

Code
(def items [{:p 1 :q 2}
            {:p 3 :q 1} 
            {:p 2 :q 3}])

(sort-by :p items)
Code
(sort-by :p items)
Comments bubble
Clojure keywords also act as functions that look up the value of their key in associative data structures
Comments bubble
Clojure keywords also act as functions that look up the value of their key in associative data structures
Doc URL
https://clojuredocs.org/clojure.core/sort-by
Doc URL
https://clojuredocs.org/clojure.core/sort-by