:: (a -> a -> Ordering) -> [a] -> a

The maximumBy function is the non-overloaded version of maximum, which takes a comparison function and a list and returns the greatest element of the list by the comparison function. The list must be finite and non-empty. We can use this to find the longest entry of a list:
>>> maximumBy (\x y -> compare (length x) (length y)) ["Hello", "World", "!", "Longest", "bar"]
"Longest"
The minimumBy function is the non-overloaded version of minimum, which 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. We can use this to find the shortest entry of a list:
>>> minimumBy (\x y -> compare (length x) (length y)) ["Hello", "World", "!", "Longest", "bar"]
"!"
The largest element of a non-empty structure with respect to the given comparison function.

Examples

Basic usage:
>>> maximumBy (compare `on` length) ["Hello", "World", "!", "Longest", "bar"]
"Longest"
WARNING: This function is partial for possibly-empty structures like lists.
The least element of a non-empty structure with respect to the given comparison function.

Examples

Basic usage:
>>> minimumBy (compare `on` length) ["Hello", "World", "!", "Longest", "bar"]
"!"
WARNING: This function is partial for possibly-empty structures like lists.
The largest element of a non-empty structure with respect to the given comparison function.
The least element of a non-empty structure with respect to the given comparison function.
O(n) Yield the maximum element of the vector according to the given comparison function. The vector may not be empty. In case of a tie, the first occurrence wins. This behavior is different from maximumBy which returns the last tie.

Examples

>>> import Data.Ord

>>> import qualified Data.Vector as V

>>> V.maximumBy (comparing fst) $ V.fromList [(2,'a'), (1,'b')]
(2,'a')

>>> V.maximumBy (comparing fst) $ V.fromList [(1,'a'), (1,'b')]
(1,'a')
O(n) Yield the minimum element of the vector according to the given comparison function. The vector may not be empty. In case of a tie, the first occurrence wins.

Examples

>>> import Data.Ord

>>> import qualified Data.Vector as V

>>> V.minimumBy (comparing fst) $ V.fromList [(2,'a'), (1,'b')]
(1,'b')

>>> V.minimumBy (comparing fst) $ V.fromList [(1,'a'), (1,'b')]
(1,'a')
O(n) Yield the maximum element of the vector according to the given comparison function. The vector may not be empty.
O(n) Yield the minimum element of the vector according to the given comparison function. The vector may not be empty.
The largest element of a non-empty structure with respect to the given comparison function.
The least element of a non-empty structure with respect to the given comparison function.
Safe version of minimumBy.