Programming-Idioms

History of Idiom 28 > diff from v42 to v43

Edit summary for version 43 :
New Clojure implementation by user [Alexander]

Version 42

2018-02-14, 15:39:34

Version 43

2019-02-16, 17:39:04

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)
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