Elm Language Lists and Iteration Sorting a list with custom comparator


Example

List.sortWith allows you to sort lists with data of any shape - you supply it with a comparison function.

compareBools : Bool -> Bool -> Order
compareBools a b =
    case (a,b) of
        (False, True) ->
            LT

        (True, False) ->
            GT

        _ ->
            EQ
        
> List.sortWith compareBools [False, True, False, True]
[False, False, True, True] : List Bool