Re: Proposal #2659: Add sortOn and friends to Data.List

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

groupOn :: Eq b => (a -> b) -> [a] -> [[a]]
I don't know how other people use groupBy, but I'm almost always looking for something of the the type Eq b => (a -> b) -> [a] -> [(b,[a])] I just bring this up as something to think about. It is easy to construct from groupOn, however it is almost as easy to construct from groupBy. So groupOn doesn't really gain me much. :) -- Russell O'Connor http://r6.ca/ ``All talk about `theft,''' the general counsel of the American Graphophone Company wrote, ``is the merest claptrap, for there exists no property in ideas musical, literary or artistic, except as defined by statute.''
participants (2)
-
Bertram Felgenhauer
-
roconnor@theorem.ca