The
minimumBy function takes a comparison function and a list
and returns the least element of the list by the comparison function.
The list must be finite and non-empty. List order is used as a
tie-breaker: if there are multiple least elements, the first of them
is chosen.
Examples
We can use this to find the shortest entry of a list:
>>> minimumBy (\x y -> compare (length x) (length y)) ["Hello", "World", "!", "Longest", "bar"]
"!"
>>> minimumBy (\(a, b) (c, d) -> compare (abs (a - b)) (abs (c - d))) [(10, 15), (1, 2), (3, 5)]
(1, 2)