sortOn
lib.sortOn
Docs pulled from | This Revision | 21 minutes ago
Sort a list based on the default comparison of a derived property b
.
The items are returned in b
-increasing order.
Performance:
The passed function f
is only evaluated once per item,
unlike an unprepared sort
using
f p < f q
.
Laws:
sortOn f == sort (p: q: f p < f q)
Inputs
f
-
1. Function argument
list
-
2. Function argument
Type
sortOn :: (a -> b) -> [a] -> [a], for comparable b
Examples
lib.lists.sortOn
usage example
sortOn stringLength [ "aa" "b" "cccc" ]
=> [ "b" "aa" "cccc" ]