    module Data.Tuple.Lazy where

    -- * Pair

    {- | Cf. '(Control.Arrow.***)'.

    Apply two functions on corresponding values in a pair,
    where the pattern match on the pair constructor is lazy.
    This is crucial in recursions such as the one of 'partition'.
    One the other hand there are applications
    where strict application is crucial,
    e.g. @mapSnd f ab@ where the left pair member is a large lazy list.
    With the lazy @mapSnd@ we make the application of @f@ depend on the whole pair @ab@.
    See "Data.Tuple.Example" for two examples
    where one variant is definitely better than the other one.
    -}
    {-
    Instead of lazy pattern matching with \code{(a,b)}
    we may use \function{fst} and \function{snd}.
    -}
    {-# INLINE mapPair #-}
    mapPair :: (a -> c, b -> d) -> (a,b) -> (c,d)
    mapPair :: forall a c b d. (a -> c, b -> d) -> (a, b) -> (c, d)
    mapPair ~(a -> c
    f,b -> d
    g) ~(a
    a,b
    b) = (a -> c
    f a
    a, b -> d
    g b
    b)

    -- | 'Control.Arrow.first'
    {-# INLINE mapFst #-}
    mapFst :: (a -> c) -> (a,b) -> (c,b)
    mapFst :: forall a c b. (a -> c) -> (a, b) -> (c, b)
    mapFst a -> c
    f ~(a
    a,b
    b) = (a -> c
    f a
    a, b
    b)

    -- | 'Control.Arrow.second'
    {-# INLINE mapSnd #-}
    mapSnd :: (b -> c) -> (a,b) -> (a,c)
    mapSnd :: forall b c a. (b -> c) -> (a, b) -> (a, c)
    mapSnd b -> c
    f ~(a
    a,b
    b) = (a
    a, b -> c
    f b
    b)

    {-# INLINE zipPair #-}
    zipPair :: (a,b) -> (c,d) -> ((a,c),(b,d))
    zipPair :: forall a b c d. (a, b) -> (c, d) -> ((a, c), (b, d))
    zipPair ~(a
    a,b
    b) ~(c
    c,d
    d) = ((a
    a,c
    c),(b
    b,d
    d))

    {-# INLINE zipWithPair #-}
    zipWithPair :: (a -> c -> e, b -> d -> f) -> (a,b) -> (c,d) -> (e,f)
    zipWithPair :: forall a c e b d f.
    (a -> c -> e, b -> d -> f) -> (a, b) -> (c, d) -> (e, f)
    zipWithPair ~(a -> c -> e
    e,b -> d -> f
    f) ~(a
    a,b
    b) ~(c
    c,d
    d) = (a -> c -> e
    e a
    a c
    c, b -> d -> f
    f b
    b d
    d)

    {-# INLINE swap #-}
    swap :: (a,b) -> (b,a)
    swap :: forall a b. (a, b) -> (b, a)
    swap ~(a
    a,b
    b) = (b
    b,a
    a)

    {-# INLINE forcePair #-}
    forcePair :: (a,b) -> (a,b)
    forcePair :: forall a b. (a, b) -> (a, b)
    forcePair ~(a
    a,b
    b) = (a
    a,b
    b)

    -- * Triple

    {-# INLINE mapTriple #-}
    mapTriple :: (a -> d, b -> e, c -> f) -> (a,b,c) -> (d,e,f)
    mapTriple :: forall a d b e c f.
    (a -> d, b -> e, c -> f) -> (a, b, c) -> (d, e, f)
    mapTriple ~(a -> d
    f,b -> e
    g,c -> f
    h) ~(a
    a,b
    b,c
    c) = (a -> d
    f a
    a, b -> e
    g b
    b, c -> f
    h c
    c)

    {-# INLINE mapFst3 #-}
    mapFst3 :: (a -> d) -> (a,b,c) -> (d,b,c)
    mapFst3 :: forall a d b c. (a -> d) -> (a, b, c) -> (d, b, c)
    mapFst3 a -> d
    f ~(a
    a,b
    b,c
    c) = (a -> d
    f a
    a, b
    b, c
    c)

    {-# INLINE mapSnd3 #-}
    mapSnd3 :: (b -> d) -> (a,b,c) -> (a,d,c)
    mapSnd3 :: forall b d a c. (b -> d) -> (a, b, c) -> (a, d, c)
    mapSnd3 b -> d
    f ~(a
    a,b
    b,c
    c) = (a
    a, b -> d
    f b
    b, c
    c)

    {-# INLINE mapThd3 #-}
    mapThd3 :: (c -> d) -> (a,b,c) -> (a,b,d)
    mapThd3 :: forall c d a b. (c -> d) -> (a, b, c) -> (a, b, d)
    mapThd3 c -> d
    f ~(a
    a,b
    b,c
    c) = (a
    a, b
    b, c -> d
    f c
    c)

    {-# INLINE zipWithTriple #-}
    zipWithTriple ::
       (a -> d -> g, b -> e -> h, c -> f -> i) -> (a,b,c) -> (d,e,f) -> (g,h,i)
    zipWithTriple :: forall a d g b e h c f i.
    (a -> d -> g, b -> e -> h, c -> f -> i)
    -> (a, b, c) -> (d, e, f) -> (g, h, i)
    zipWithTriple ~(a -> d -> g
    g,b -> e -> h
    h,c -> f -> i
    i) ~(a
    a,b
    b,c
    c) ~(d
    d,e
    e,f
    f) = (a -> d -> g
    g a
    a d
    d, b -> e -> h
    h b
    b e
    e, c -> f -> i
    i c
    c f
    f)

    {-# INLINE uncurry3 #-}
    uncurry3 :: (a -> b -> c -> d) -> ((a, b, c) -> d)
    uncurry3 :: forall a b c d. (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