{-# LANGUAGE TupleSections #-}
module Data.Tuple.Extra(
module Data.Tuple,
first, second, (***), (&&&),
dupe, both,
firstM, secondM,
fst3, snd3, thd3,
first3, second3, third3,
curry3, uncurry3
) where
import Data.Tuple
import qualified Control.Arrow as Arrow
infixr 3 ***, &&&
first :: (a -> a') -> (a, b) -> (a', b)
first :: (a -> a') -> (a, b) -> (a', b)
first = (a -> a') -> (a, b) -> (a', b)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
Arrow.first
second :: (b -> b') -> (a, b) -> (a, b')
second :: (b -> b') -> (a, b) -> (a, b')
second = (b -> b') -> (a, b) -> (a, b')
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
Arrow.second
firstM :: Functor m => (a -> m a') -> (a, b) -> m (a', b)
firstM :: (a -> m a') -> (a, b) -> m (a', b)
firstM a -> m a'
f (a
a,b
b) = (,b
b) (a' -> (a', b)) -> m a' -> m (a', b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> m a'
f a
a
secondM :: Functor m => (b -> m b') -> (a, b) -> m (a, b')
secondM :: (b -> m b') -> (a, b) -> m (a, b')
secondM b -> m b'
f (a
a,b
b) = (a
a,) (b' -> (a, b')) -> m b' -> m (a, b')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> m b'
f b
b
(***) :: (a -> a') -> (b -> b') -> (a, b) -> (a', b')
*** :: (a -> a') -> (b -> b') -> (a, b) -> (a', b')
(***) = (a -> a') -> (b -> b') -> (a, b) -> (a', b')
forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
(Arrow.***)
(&&&) :: (a -> b) -> (a -> c) -> a -> (b, c)
&&& :: (a -> b) -> (a -> c) -> a -> (b, c)
(&&&) = (a -> b) -> (a -> c) -> a -> (b, c)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
(Arrow.&&&)
dupe :: a -> (a,a)
dupe :: a -> (a, a)
dupe a
x = (a
x,a
x)
both :: (a -> b) -> (a, a) -> (b, b)
both :: (a -> b) -> (a, a) -> (b, b)
both a -> b
f (a
x,a
y) = (a -> b
f a
x, a -> b
f a
y)
fst3 :: (a,b,c) -> a
fst3 :: (a, b, c) -> a
fst3 (a
a,b
b,c
c) = a
a
snd3 :: (a,b,c) -> b
snd3 :: (a, b, c) -> b
snd3 (a
a,b
b,c
c) = b
b
thd3 :: (a,b,c) -> c
thd3 :: (a, b, c) -> c
thd3 (a
a,b
b,c
c) = c
c
curry3 :: ((a, b, c) -> d) -> a -> b -> c -> d
curry3 :: ((a, b, c) -> d) -> a -> b -> c -> d
curry3 (a, b, c) -> d
f a
a b
b c
c = (a, b, c) -> d
f (a
a,b
b,c
c)
uncurry3 :: (a -> b -> c -> d) -> ((a, b, c) -> d)
uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d
uncurry3 a -> b -> c -> d
f ~(a
a,b
b,c
c) = a -> b -> c -> d
f a
a b
b c
c
first3 :: (a -> a') -> (a, b, c) -> (a', b, c)
first3 :: (a -> a') -> (a, b, c) -> (a', b, c)
first3 a -> a'
f (a
a,b
b,c
c) = (a -> a'
f a
a,b
b,c
c)
second3 :: (b -> b') -> (a, b, c) -> (a, b', c)
second3 :: (b -> b') -> (a, b, c) -> (a, b', c)
second3 b -> b'
f (a
a,b
b,c
c) = (a
a,b -> b'
f b
b,c
c)
third3 :: (c -> c') -> (a, b, c) -> (a, b, c')
third3 :: (c -> c') -> (a, b, c) -> (a, b, c')
third3 c -> c'
f (a
a,b
b,c
c) = (a
a,b
b,c -> c'
f c
c)