>>> maximumBy (\x y -> compare (length x) (length y)) ["Hello", "World", "!", "Longest", "bar"] "Longest"
>>> minimumBy (\x y -> compare (length x) (length y)) ["Hello", "World", "!", "Longest", "bar"] "!"
>>> maximumBy (compare `on` length) ["Hello", "World", "!", "Longest", "bar"] "Longest"WARNING: This function is partial for possibly-empty structures like lists.
>>> minimumBy (compare `on` length) ["Hello", "World", "!", "Longest", "bar"] "!"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 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')