[GHC] #9337: Add `sortOn` function to Data.List

GHC ghc-devs at haskell.org
Sun Jul 20 22:12:30 UTC 2014


#9337: Add `sortOn` function to Data.List
-------------------------------------+-------------------------------------
        Reporter:  JohnWiegley       |                   Owner:
            Type:  feature request   |                  Status:  new
        Priority:  normal            |               Milestone:  7.10.1
       Component:  libraries/base    |                 Version:  7.8.3
        Keywords:                    |  Differential Revisions:
Operating System:  Unknown/Multiple  |            Architecture:
 Type of failure:  None/Unknown      |  Unknown/Multiple
       Test Case:                    |              Difficulty:  Easy (less
        Blocking:                    |  than 1 hour)
                                     |              Blocked By:
                                     |         Related Tickets:
-------------------------------------+-------------------------------------
 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))
 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9337>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list