Function to add to Data.List

Herbert Valerio Riedel hvr at gnu.org
Thu Apr 10 09:37:29 UTC 2014


On 2014-04-05 at 23:53:04 +0200, John Wiegley wrote:
> 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.

+1 with a preference on naming it 'Data.List.sortOn'

(and I retract my suggestion of using RULES)




PS: Btw, I'd suggest making 'Schwarzian transform' in the docstring into a Haddock link:

    <http://en.wikipedia.org/wiki/Schwartzian_transform Schwartzian transform>


More information about the Libraries mailing list