By default, List.sort
sorts in ascending order.
> List.sort [3,1,5]
[1,3,5] : List number
List.sort
needs the list elements to be comparable
. That means: String
, Char
, number
(Int
and Float
), List
of comparable
or tuple of comparable
.
> List.sort [(5,"ddd"),(4,"zzz"),(5,"aaa")]
[(4,"zzz"),(5,"aaa"),(5,"ddd")] : List ( number, String )
> List.sort [[3,4],[2,3],[4,5],[1,2]]
[[1,2],[2,3],[3,4],[4,5]] : List (List number)
You can't sort lists of Bool
or objects with List.sort
. For that see Sorting a list with custom comparator.
> List.sort [True, False]
-- error, can't compare Bools