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

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.Strict 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.Strict as V

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

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