sort-by orders a collection by applying a one-argument key function to each element, then comparing the resulting keys. It uses compare by default or accepts an explicit comparator, returning an ordered sequence. section 8.3.5
Sorting by a map key
(sort-by :age [{:age 65} {:age 13} {:age 8}]) ;; ({:age 8} {:age 13} {:age 65}) The key function can also transform values before comparison: (sort-by str [:f "s" \c 'u]) orders unlike values by their string representations.
Use the contract to choose inputs and comparators:
- Pass a collection supported by seq; transients and scalars are rejected. section 8.3.5
- Ensure elements or computed keys are mutually sortable, or ClassCastException may result. section 8.3.5
