>>> maximumBy (\x y -> compare (length x) (length y)) ["Hello", "World", "!", "Longest", "bar"] "Longest"
>>> minimumBy (\(a, b) (c, d) -> compare (abs (a - b)) (abs (c - d))) [(10, 15), (1, 2), (3, 5)] (10, 15)
>>> minimumBy (\x y -> compare (length x) (length y)) ["Hello", "World", "!", "Longest", "bar"] "!"
>>> minimumBy (\(a, b) (c, d) -> compare (abs (a - b)) (abs (c - d))) [(10, 15), (1, 2), (3, 5)] (1, 2)
>>> 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.
>>> 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.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.Strict 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')