Function to add to Data.List -> Key.sort

Henning Thielemann schlepptop at henning-thielemann.de
Sat Apr 5 21:58:12 UTC 2014


Am 05.04.2014 23:53, schrieb John Wiegley:
> I heard a talk that mentioned this transform today at Hac NYC, and was
> surprised it wasn't already in Data.List:
>
>      -- | Sort a list using a key on each element.  This implements the
>      --   decorate-sort-undecorate paradigm, also called a Schwarzian transform.
>      sortByKey :: Ord b => (a -> b) -> [a] -> [a]
>      sortByKey f = map snd . sortBy (comparing fst) . map (\x -> (f x, x))
>
> I would like to propose adding it.

I have it as Data.List.Key.sort in utility-ht.



More information about the Libraries mailing list