{-# LANGUAGE TupleSections #-}
module Relude.Extra.Tuple
( dup
, dupe
, mapToFst
, mapToSnd
, mapBoth
, traverseToFst
, traverseToSnd
, traverseBoth
) where
import Relude
dup :: a -> (a, a)
dup :: a -> (a, a)
dup a :: a
a = (a
a, a
a)
{-# INLINE dup #-}
dupe :: a -> (a, a)
dupe :: a -> (a, a)
dupe = a -> (a, a)
forall a. a -> (a, a)
dup
{-# DEPRECATED dupe "Use 'dup' instead, it has more idiomatic and common name" #-}
mapToFst :: (a -> b) -> a -> (b, a)
mapToFst :: (a -> b) -> a -> (b, a)
mapToFst f :: a -> b
f a :: a
a = (a -> b
f a
a, a
a)
{-# INLINE mapToFst #-}
mapToSnd :: (a -> b) -> a -> (a, b)
mapToSnd :: (a -> b) -> a -> (a, b)
mapToSnd f :: a -> b
f a :: a
a = (a
a, a -> b
f a
a)
{-# INLINE mapToSnd #-}
mapBoth :: (a -> b) -> (a, a) -> (b, b)
mapBoth :: (a -> b) -> (a, a) -> (b, b)
mapBoth f :: a -> b
f (a1 :: a
a1, a2 :: a
a2) = (a -> b
f a
a1, a -> b
f a
a2)
{-# DEPRECATED mapBoth "Use 'Relude.Extra.Bifunctor.bimapBoth' from \"Relude.Extra.Bifunctor\" instead" #-}
{-# INLINE mapBoth #-}
traverseToFst :: Functor t => (a -> t b) -> a -> t (b, a)
traverseToFst :: (a -> t b) -> a -> t (b, a)
traverseToFst f :: a -> t b
f a :: a
a = (,a
a) (b -> (b, a)) -> t b -> t (b, a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> t b
f a
a
{-# INLINE traverseToFst #-}
traverseToSnd :: Functor t => (a -> t b) -> a -> t (a, b)
traverseToSnd :: (a -> t b) -> a -> t (a, b)
traverseToSnd f :: a -> t b
f a :: a
a = (a
a,) (b -> (a, b)) -> t b -> t (a, b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> t b
f a
a
{-# INLINE traverseToSnd #-}
traverseBoth :: Applicative t => (a -> t b) -> (a, a) -> t (b, b)
traverseBoth :: (a -> t b) -> (a, a) -> t (b, b)
traverseBoth f :: a -> t b
f (a1 :: a
a1, a2 :: a
a2) = (,) (b -> b -> (b, b)) -> t b -> t (b -> (b, b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> t b
f a
a1 t (b -> (b, b)) -> t b -> t (b, b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> t b
f a
a2
{-# INLINE traverseBoth #-}