{-# 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 :: (a -> b) -> f a a -> f b b
bimapBoth f :: a -> b
f = (a -> b) -> (a -> b) -> f a a -> f b b
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 :: (a -> c) -> (b -> d) -> f (p a b) -> f (p c d)
bimapF f :: a -> c
f g :: b -> d
g = (p a b -> p c d) -> f (p a b) -> f (p c d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> c) -> (b -> d) -> p a b -> p c 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 :: (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 (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 (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 :: (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 (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 (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second
{-# INLINE secondF #-}