Proposal: Add `maxOn` and `minOn` functions to Data.Ord

Daniel Díaz Casanueva dhelta.diaz at gmail.com
Fri May 27 18:51:19 UTC 2016


I think these are useful in general, and that they would make a good
addition to `Data.Ord`. The names are inspired by `sortOn`. Definitions:

```
minOn :: Ord b => (a -> b) -> a -> a -> a
minOn f x y =
  case comparing f x y of
    LT -> x
    _ -> y

maxOn :: Ord b => (a -> b) -> a -> a -> a
maxOn f x y =
  case comparing f x y of
    GT -> x
    _ -> y
```

These don't need to be the exact definitions, but they convey the semantics
I'm looking for.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20160527/571e53fb/attachment.html>


More information about the Libraries mailing list