Skip to content

Add sortOn and other *On functions

Almost all uses of sortBy are of the form sortBy (comparing f), sortBy (compare on f) or an equivalent construction. I propose that we add the more convenient function sortOn to Data.List:

sortOn          :: Ord b => (a -> b) -> [a] -> [a]

For consistency for the other By functions we should also add an On equivalent:

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
Trac metadata
Trac field Value
Version 6.9
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component libraries/base
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
Edited by Ian Lynagh -
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information