Introduce shortcut for "on (==)" much like there's a shortcut for "on compare".
A common use case for on
(from Data.Function
) is to use it with compare
, e.g. compare
on snd
. In fact, this pattern is so common that there's a convenient comparing
function which provides a shortcut for this use case such that one can write
sortBy (comparing snd)
instead of
sortBy (compare `on` snd)
I think another common use case is to use on
together with (==)
as in
groupBy ((==) `on` snd)
In a similiar vein as with comparing
, I think it would be nice if there was a function which encapsulates this use case, like
equating :: Eq b => (a -> b) -> a -> a -> Bool
equating = on (==)
such that one can write
groupBy (equating snd)
The (IMHO fairly nice) name equating
is not my idea but was suggested by //ClaudiusMaximus// of #haskell fame.
Trac metadata
Trac field | Value |
---|---|
Version | 7.8.2 |
Type | FeatureRequest |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | libraries/base |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | ekmett, hvr |
Operating system | |
Architecture |