>>> maximumBy (compare `on` length) ["Hello", "World", "!", "Longest", "bar"] "Longest"WARNING: This function is partial for possibly-empty structures like lists.
>>> 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')
>>> import Data.Ord >>> import qualified Data.Vector.Strict 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')
>>> import Data.Ord >>> import qualified Data.Vector.Unboxed as VU >>> VU.maximumBy (comparing fst) $ VU.fromList [(2,'a'), (1 :: Int,'b')] (2,'a') >>> VU.maximumBy (comparing fst) $ VU.fromList [(1,'a'), (1 :: Int,'b')] (1,'a')
>>> bimaximumBy compare (42, 17) 42
>>> bimaximumBy compare (Left 17) 17
>>> bimaximumBy compare (BiList [42, 17, 23] [-5, 18]) 42On empty structures, this function throws an exception:
>>> bimaximumBy compare (BiList [] []) *** Exception: bifoldr1: empty structure ...