bimap -package:bimap package:relude

Map over both arguments at the same time.
bimap f g ≡ first f . second g

Examples

>>> bimap toUpper (+1) ('j', 3)
('J',4)
>>> bimap toUpper (+1) (Left 'j')
Left 'J'
>>> bimap toUpper (+1) (Right 3)
Right 4
Maps a function over both elements of a bifunctor.
>>> bimapBoth length ([True], [False, True])
(1,2)

>>> map (bimapBoth not) [Left True, Right False]
[Left False,Right True]
Fmaps functions for nested bifunctor. Short for fmap (bimap f g).
>>> bimapF not length $ Just (False, ['a', 'b'])
Just (True,2)
A default definition of bimap in terms of the Bitraversable operations.
bimapDefault f g ≡
runIdentity . bitraverse (Identity . f) (Identity . g)