relude-0.6.0.0: Custom prelude from Kowainik
Copyright(c) 2018-2019 Kowainik
LicenseMIT
MaintainerKowainik <xrom.xkov@gmail.com>
Safe HaskellSafe
LanguageHaskell2010

Relude.Extra.Bifunctor

Description

Useful combinators for bifunctors inside functors. This set of functions is useful when you want to work with types like these ones:

foo :: IO (Either a b)
bar :: IO (a, b)

baz :: Maybe (Either a b)
qux :: Maybe (a, b)

doo :: (a, a)
dee :: Either a a
Synopsis

Documentation

bimapBoth :: Bifunctor f => (a -> b) -> f a a -> f b b Source #

Maps a function over both elements of a bifunctor.

>>> bimapBoth length ("a", "bb")
(1,2)
>>> map (bimapBoth not) [Left True, Right False]
[Left False,Right True]

Since: 0.6.0.0

bimapF :: (Functor f, Bifunctor p) => (a -> c) -> (b -> d) -> f (p a b) -> f (p c d) Source #

Fmaps functions for nested bifunctor. Short for fmap (bimap f g).

>>> bimapF not length $ Just (False, ['a', 'b'])
Just (True,2)

firstF :: (Functor f, Bifunctor p) => (a -> c) -> f (p a b) -> f (p c b) Source #

Short for fmap . first.

>>> firstF not $ Just (False, ['a', 'b'])
Just (True,"ab")

secondF :: (Functor f, Bifunctor p) => (b -> d) -> f (p a b) -> f (p a d) Source #

Short for fmap . second.

>>> secondF length  $ Just (False, ['a', 'b'])
Just (False,2)