Open jachymb opened 7 years ago
Personally, I'm not sure if this crosses the Fairbairn threshold in my mind, since literally every bifunctorial function in this library could have a variant like this. I'm similarly skeptical about combinators like ~bimap f id
~, bifoldMap f (const mempty)
, etc.
That being said, Data.Bifunctor.Join
already gives you what you want:
bothmap :: Bifunctor f => (a -> b) -> f a a -> f b b
bothmap f = runJoin . fmap f . Join
bimap f id = second
, no?
Oops, I misspoke about bimap f id
, then.
btw, speaking of "join", you can of course also have:
import Control.Monad (join)
bothmap :: Bifunctor f => (a -> b) -> f a a -> f b b
bothmap = join bimap
We have both
in lens
. We could had it in Data.Bitraversable
, but not sure it worth the trouble.
join bimap
bothmap
Former is not much longer, is it?
I often use something like this:
I typically use it with pairs where function
f
is a lambda expression and I'm lazy to bind it to a name. It would be nice to have it in the library.