bimap -package:relude -is:module

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
Bidirectional mapping between two key types A data structure representing a bidirectional mapping between two key types. Each value in the bimap is associated with exactly one value of the opposite type.
Transform a graph by applying given functions to the vertices of each part. Complexity: O((n + m) * log(n)) time.
bimap f g empty           == empty
bimap f g . vertex        == vertex . Data.Bifunctor.bimap f g
bimap f g (edge x y)      == edge (f x) (g y)
bimap id id               == id
bimap f1 g1 . bimap f2 g2 == bimap (f1 . f2) (g1 . g2)
Map over both sides of a symbolic Either at the same time
>>> let f = uninterpret "f" :: SInteger -> SInteger

>>> let g = uninterpret "g" :: SInteger -> SInteger

>>> prove $ \x -> fromLeft (bimap f g (sLeft x)) .== f x
Q.E.D.

>>> prove $ \x -> fromRight (bimap f g (sRight x)) .== g x
Q.E.D.
Map over the both types of entries of an AltList.
bimap f g ≡ second g . first f
A bidirectional map between values of types a and b.
Bidirectional map. Essentially, a bijection between subsets of its two argument types. For one value of the left-hand type this map contains one value of the right-hand type and vice versa.
Type-level bimap.
>>> :kind! Eval (Bimap ((+) 1) (Flip (-) 1) '(2, 4))
Eval (Bimap ((+) 1) (Flip (-) 1) '(2, 4)) :: (Nat, Nat)
= '(3, 3)
Finite maps from k to v, with a way to quickly get from v to k for certain values of type v (those for which tag is defined). Every value of this type must satisfy biMapInvariant.
Bijection between finite sets. Both data types are strict here.
Alias for bitraverse_.
The bimapAccumL function behaves like a combination of bimap and bifoldl; it traverses a structure from left to right, threading a state of type a and using the given actions to compute new elements for the structure.

Examples

Basic usage:
>>> bimapAccumL (\acc bool -> (acc + 1, show bool)) (\acc string -> (acc * 2, reverse string)) 3 (True, "foo")
(8,("True","oof"))
The bimapAccumR function behaves like a combination of bimap and bifoldr; it traverses a structure from right to left, threading a state of type a and using the given actions to compute new elements for the structure.

Examples

Basic usage:
>>> bimapAccumR (\acc bool -> (acc + 1, show bool)) (\acc string -> (acc * 2, reverse string)) 3 (True, "foo")
(7,("True","oof"))
A default definition of bimap in terms of the Bitraversable operations.
bimapDefault f g ≡
runIdentity . bitraverse (Identity . f) (Identity . g)
Alias for bitraverse.
Lift two Isos into both arguments of a Bifunctor.
bimapping :: Bifunctor p => Iso s t a b -> Iso s' t' a' b' -> Iso (p s s') (p t t') (p a a') (p b b')
bimapping :: Bifunctor p => Iso' s a -> Iso' s' a' -> Iso' (p s s') (p a a')