{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

module Data.Traversable.Unzip.EagerPair (EagerPair (..)) where
import Data.Biapplicative (Bifunctor (..), Biapplicative (..))

newtype EagerPair a b = EagerPair { forall a b. EagerPair a b -> (a, b)
unEagerPair :: (a, b) }
  deriving newtype ((forall a b. (a -> b) -> EagerPair a a -> EagerPair a b)
-> (forall a b. a -> EagerPair a b -> EagerPair a a)
-> Functor (EagerPair a)
forall a b. a -> EagerPair a b -> EagerPair a a
forall a b. (a -> b) -> EagerPair a a -> EagerPair a b
forall a a b. a -> EagerPair a b -> EagerPair a a
forall a a b. (a -> b) -> EagerPair a a -> EagerPair a b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a a b. (a -> b) -> EagerPair a a -> EagerPair a b
fmap :: forall a b. (a -> b) -> EagerPair a a -> EagerPair a b
$c<$ :: forall a a b. a -> EagerPair a b -> EagerPair a a
<$ :: forall a b. a -> EagerPair a b -> EagerPair a a
Functor)

instance Bifunctor EagerPair where
  bimap :: forall a b c d.
(a -> b) -> (c -> d) -> EagerPair a c -> EagerPair b d
bimap a -> b
f c -> d
g (EagerPair (a
a, c
b)) = (b, d) -> EagerPair b d
forall a b. (a, b) -> EagerPair a b
EagerPair (a -> b
f a
a, c -> d
g c
b)

instance Biapplicative EagerPair where
  bipure :: forall a b. a -> b -> EagerPair a b
bipure a
a b
b = (a, b) -> EagerPair a b
forall a b. (a, b) -> EagerPair a b
EagerPair (a
a, b
b)
  biliftA2 :: forall a b c d e f.
(a -> b -> c)
-> (d -> e -> f) -> EagerPair a d -> EagerPair b e -> EagerPair c f
biliftA2 a -> b -> c
f d -> e -> f
g (EagerPair (a
a, d
b)) (EagerPair (b
x, e
y))
    = (c, f) -> EagerPair c f
forall a b. (a, b) -> EagerPair a b
EagerPair (a -> b -> c
f a
a b
x, d -> e -> f
g d
b e
y)