{-# LANGUAGE Safe #-}
module Relude.Extra.Bifunctor
( bimapBoth
, bimapF
, firstF
, secondF
) where
import Relude
bimapBoth :: Bifunctor f => (a -> b) -> f a a -> f b b
bimapBoth :: forall (f :: * -> * -> *) a b.
Bifunctor f =>
(a -> b) -> f a a -> f b b
bimapBoth a -> b
f = (a -> b) -> (a -> b) -> f a a -> f b b
forall a b c d. (a -> b) -> (c -> d) -> f a c -> f b d
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap a -> b
f a -> b
f
{-# INLINE bimapBoth #-}
bimapF :: (Functor f, Bifunctor p) => (a -> c) -> (b -> d) -> f (p a b) -> f (p c d)
bimapF :: forall (f :: * -> *) (p :: * -> * -> *) a c b d.
(Functor f, Bifunctor p) =>
(a -> c) -> (b -> d) -> f (p a b) -> f (p c d)
bimapF a -> c
f b -> d
g = (p a b -> p c d) -> f (p a b) -> f (p c d)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> c) -> (b -> d) -> p a b -> p c d
forall a b c d. (a -> b) -> (c -> d) -> p a c -> p b d
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap a -> c
f b -> d
g)
{-# INLINE bimapF #-}
firstF :: (Functor f, Bifunctor p) => (a -> c) -> f (p a b) -> f (p c b)
firstF :: forall (f :: * -> *) (p :: * -> * -> *) a c b.
(Functor f, Bifunctor p) =>
(a -> c) -> f (p a b) -> f (p c b)
firstF = (p a b -> p c b) -> f (p a b) -> f (p c b)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((p a b -> p c b) -> f (p a b) -> f (p c b))
-> ((a -> c) -> p a b -> p c b)
-> (a -> c)
-> f (p a b)
-> f (p c b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> c) -> p a b -> p c b
forall a b c. (a -> b) -> p a c -> p b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first
{-# INLINE firstF #-}
secondF :: (Functor f, Bifunctor p) => (b -> d) -> f (p a b) -> f (p a d)
secondF :: forall (f :: * -> *) (p :: * -> * -> *) b d a.
(Functor f, Bifunctor p) =>
(b -> d) -> f (p a b) -> f (p a d)
secondF = (p a b -> p a d) -> f (p a b) -> f (p a d)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((p a b -> p a d) -> f (p a b) -> f (p a d))
-> ((b -> d) -> p a b -> p a d)
-> (b -> d)
-> f (p a b)
-> f (p a d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> d) -> p a b -> p a d
forall b c a. (b -> c) -> p a b -> p a c
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second
{-# INLINE secondF #-}