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): The list to sort
  • compare ((t0, t0) -> int): Orders two elements: negative, zero or positive

Returns: List

Example

listSortBy(["bb", "a"], fn(x, y) => length(x) - length(y))  // ["a", "bb"]
listSortBy (["bb", "a"], \(x, y) => length x - length y)  // ["a", "bb"]