:: Ord b => (a -> b) -> [a] -> a

A version of maximum where the comparison is done on some extracted value. Raises an error if the list is empty. Only calls the function once per element.
maximumOn id [] == undefined
maximumOn length ["test","extra","a"] == "extra"
A version of minimum where the comparison is done on some extracted value. Raises an error if the list is empty. Only calls the function once per element.
minimumOn id [] == undefined
minimumOn length ["test","extra","a"] == "a"
argmin
argmax
O(n) Yield the maximum element of the vector by comparing the results of a key function on each element. In case of a tie, the first occurrence wins. The vector may not be empty.

Examples

>>> import qualified Data.Vector as V

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

>>> V.maximumOn fst $ V.fromList [(1,'a'), (1,'b')]
(1,'a')
O(n) Yield the minimum element of the vector by comparing the results of a key function on each element. In case of a tie, the first occurrence wins. The vector may not be empty.

Examples

>>> import qualified Data.Vector as V

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

>>> V.minimumOn fst $ V.fromList [(1,'a'), (1,'b')]
(1,'a')
The largest element of a non-empty data structure with respect to the given comparison function.
>>> maximumOn1 abs (0 :| [2, 1, -3, -2])
-3
The smallest element of a non-empty data structure with respect to the given comparison function.
>>> minimumOn1 abs (0 :| [2, 1, -3, -2])
0