Add `sortOn` function to Data.List
This passed the vote on the libraries list a while ago, but I forget to add a ticket. The request was to add sortOn to Data.List:
-- | Sort a list using a key on each element. This implements the
-- decorate-sort-undecorate paradigm, also called a Schwarzian transform.
sortOn :: Ord b => (a -> b) -> [a] -> [a]
sortOn f = map snd . sortBy (comparing fst) . map (\x -> (f x, x))
Trac metadata
| Trac field | Value |
|---|---|
| Version | 7.8.3 |
| Type | FeatureRequest |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | libraries/base |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | ekmett, hvr |
| Operating system | |
| Architecture |