The
mapBoth function takes two functions and applies the first
if iff the value takes the form
Left _ and the second
if the value takes the form
Right _.
Using
Data.Bifunctor:
mapBoth = bimap
Using
Control.Arrow:
mapBoth = (+++)
>>> mapBoth (*2) (*3) (Left 4)
Left 8
>>> mapBoth (*2) (*3) (Right 4)
Right 12