listSortBy (Function)
Signature: listSortBy(list: List<t0>, compare: (t0, t0) -> int) -> List<t0>
Description: Returns a new list sorted by a comparator, for any element type. The comparator returns a negative int when its first argument comes first, a positive int when it comes second and zero to keep the two in their original order: the sort is stable.
Parameters
- list (
List<t0>): The list to sort - compare (
(t0, t0) -> int): Orders two elements: negative, zero or positive
Returns: List<t0>
Example
let ordered = listSortBy(["bb", "a"], fn(x, y) => satSub(length(x), length(y))) // ["a", "bb"]
ordered = listSortBy (["bb", "a"], \(x, y) => satSub (length x, length y)) // ["a", "bb"]