Proposal #2659: Add sortOn and friends to Data.List
Bertram Felgenhauer
bertram.felgenhauer at googlemail.com
Wed Oct 8 08:03:37 EDT 2008
Twan van Laarhoven wrote:
> Hello list,
>
>
> Almost all uses of sortBy in user code use 'comparing', 'on' or a similar
> construction [1]. I think we should add a function that makes this common
> behavior more convenient:
>
> sortOn :: Ord b => (a -> b) -> [a] -> [a]
>
> For consistency we should also add *On for the other *By functions in
> Data.List:
>
> nubOn :: Eq b => (a -> b) -> [a] -> [a]
> deleteOn :: Eq b => (a -> b) -> a -> [a] -> [a]
> deleteFirstsOn :: Eq b => (a -> b) -> [a] -> [a] -> [a]
> unionOn :: Eq b => (a -> b) -> [a] -> [a] -> [a]
> intersectOn :: Eq b => (a -> b) -> [a] -> [a] -> [a]
> groupOn :: Eq b => (a -> b) -> [a] -> [[a]]
> sortOn :: Ord b => (a -> b) -> [a] -> [a]
> insertOn :: Ord b => (a -> b) -> a -> [a] -> [a]
> maximumOn :: Ord b => (a -> b) -> [a] -> a
> minimumOn :: Ord b => (a -> b) -> [a] -> a
> (nubSortOn :: Ord b => (a -> b) -> [a] -> [a]) -- see #2629
Too many functions, and too little added functionality, IMHO.
> newtype Down a = Down { getDown :: a }
I like this one.
Bertram
More information about the Libraries
mailing list