-- | Internal types module to house types that would require mutual recursion at the module level if defined separately
module Unison.Merge.Internal.Types
  ( GThreeWay (..),
    ThreeWay (..),
    TwoOrThreeWay (..),
    TwoWay (..),
  )
where

import Control.DeepSeq (NFData)
import Data.Semialign (Semialign, Unzip, Zip, alignWith, unzipWith, zipWith)
import Data.Semigroup.Generic (GenericSemigroupMonoid (..))
import Data.These (These (..))
import Unison.Prelude
import Prelude hiding (zipWith)

data GThreeWay a b = GThreeWay
  { forall a b. GThreeWay a b -> a
lca :: a,
    forall a b. GThreeWay a b -> b
alice :: b,
    forall a b. GThreeWay a b -> b
bob :: b
  }
  deriving stock ((forall x. GThreeWay a b -> Rep (GThreeWay a b) x)
-> (forall x. Rep (GThreeWay a b) x -> GThreeWay a b)
-> Generic (GThreeWay a b)
forall x. Rep (GThreeWay a b) x -> GThreeWay a b
forall x. GThreeWay a b -> Rep (GThreeWay a b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a b x. Rep (GThreeWay a b) x -> GThreeWay a b
forall a b x. GThreeWay a b -> Rep (GThreeWay a b) x
$cfrom :: forall a b x. GThreeWay a b -> Rep (GThreeWay a b) x
from :: forall x. GThreeWay a b -> Rep (GThreeWay a b) x
$cto :: forall a b x. Rep (GThreeWay a b) x -> GThreeWay a b
to :: forall x. Rep (GThreeWay a b) x -> GThreeWay a b
Generic)

data ThreeWay a = ThreeWay
  { forall a. ThreeWay a -> a
lca :: !a,
    forall a. ThreeWay a -> a
alice :: !a,
    forall a. ThreeWay a -> a
bob :: !a
  }
  deriving stock ((forall m. Monoid m => ThreeWay m -> m)
-> (forall m a. Monoid m => (a -> m) -> ThreeWay a -> m)
-> (forall m a. Monoid m => (a -> m) -> ThreeWay a -> m)
-> (forall a b. (a -> b -> b) -> b -> ThreeWay a -> b)
-> (forall a b. (a -> b -> b) -> b -> ThreeWay a -> b)
-> (forall b a. (b -> a -> b) -> b -> ThreeWay a -> b)
-> (forall b a. (b -> a -> b) -> b -> ThreeWay a -> b)
-> (forall a. (a -> a -> a) -> ThreeWay a -> a)
-> (forall a. (a -> a -> a) -> ThreeWay a -> a)
-> (forall a. ThreeWay a -> [a])
-> (forall a. ThreeWay a -> Bool)
-> (forall a. ThreeWay a -> Int)
-> (forall a. Eq a => a -> ThreeWay a -> Bool)
-> (forall a. Ord a => ThreeWay a -> a)
-> (forall a. Ord a => ThreeWay a -> a)
-> (forall a. Num a => ThreeWay a -> a)
-> (forall a. Num a => ThreeWay a -> a)
-> Foldable ThreeWay
forall a. Eq a => a -> ThreeWay a -> Bool
forall a. Num a => ThreeWay a -> a
forall a. Ord a => ThreeWay a -> a
forall m. Monoid m => ThreeWay m -> m
forall a. ThreeWay a -> Bool
forall a. ThreeWay a -> Int
forall a. ThreeWay a -> [a]
forall a. (a -> a -> a) -> ThreeWay a -> a
forall m a. Monoid m => (a -> m) -> ThreeWay a -> m
forall b a. (b -> a -> b) -> b -> ThreeWay a -> b
forall a b. (a -> b -> b) -> b -> ThreeWay a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => ThreeWay m -> m
fold :: forall m. Monoid m => ThreeWay m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> ThreeWay a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> ThreeWay a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> ThreeWay a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> ThreeWay a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> ThreeWay a -> b
foldr :: forall a b. (a -> b -> b) -> b -> ThreeWay a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> ThreeWay a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> ThreeWay a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> ThreeWay a -> b
foldl :: forall b a. (b -> a -> b) -> b -> ThreeWay a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> ThreeWay a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> ThreeWay a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> ThreeWay a -> a
foldr1 :: forall a. (a -> a -> a) -> ThreeWay a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> ThreeWay a -> a
foldl1 :: forall a. (a -> a -> a) -> ThreeWay a -> a
$ctoList :: forall a. ThreeWay a -> [a]
toList :: forall a. ThreeWay a -> [a]
$cnull :: forall a. ThreeWay a -> Bool
null :: forall a. ThreeWay a -> Bool
$clength :: forall a. ThreeWay a -> Int
length :: forall a. ThreeWay a -> Int
$celem :: forall a. Eq a => a -> ThreeWay a -> Bool
elem :: forall a. Eq a => a -> ThreeWay a -> Bool
$cmaximum :: forall a. Ord a => ThreeWay a -> a
maximum :: forall a. Ord a => ThreeWay a -> a
$cminimum :: forall a. Ord a => ThreeWay a -> a
minimum :: forall a. Ord a => ThreeWay a -> a
$csum :: forall a. Num a => ThreeWay a -> a
sum :: forall a. Num a => ThreeWay a -> a
$cproduct :: forall a. Num a => ThreeWay a -> a
product :: forall a. Num a => ThreeWay a -> a
Foldable, (forall a b. (a -> b) -> ThreeWay a -> ThreeWay b)
-> (forall a b. a -> ThreeWay b -> ThreeWay a) -> Functor ThreeWay
forall a b. a -> ThreeWay b -> ThreeWay a
forall a b. (a -> b) -> ThreeWay a -> ThreeWay 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 b. (a -> b) -> ThreeWay a -> ThreeWay b
fmap :: forall a b. (a -> b) -> ThreeWay a -> ThreeWay b
$c<$ :: forall a b. a -> ThreeWay b -> ThreeWay a
<$ :: forall a b. a -> ThreeWay b -> ThreeWay a
Functor, (forall x. ThreeWay a -> Rep (ThreeWay a) x)
-> (forall x. Rep (ThreeWay a) x -> ThreeWay a)
-> Generic (ThreeWay a)
forall x. Rep (ThreeWay a) x -> ThreeWay a
forall x. ThreeWay a -> Rep (ThreeWay a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (ThreeWay a) x -> ThreeWay a
forall a x. ThreeWay a -> Rep (ThreeWay a) x
$cfrom :: forall a x. ThreeWay a -> Rep (ThreeWay a) x
from :: forall x. ThreeWay a -> Rep (ThreeWay a) x
$cto :: forall a x. Rep (ThreeWay a) x -> ThreeWay a
to :: forall x. Rep (ThreeWay a) x -> ThreeWay a
Generic, Functor ThreeWay
Foldable ThreeWay
(Functor ThreeWay, Foldable ThreeWay) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> ThreeWay a -> f (ThreeWay b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    ThreeWay (f a) -> f (ThreeWay a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> ThreeWay a -> m (ThreeWay b))
-> (forall (m :: * -> *) a.
    Monad m =>
    ThreeWay (m a) -> m (ThreeWay a))
-> Traversable ThreeWay
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => ThreeWay (m a) -> m (ThreeWay a)
forall (f :: * -> *) a.
Applicative f =>
ThreeWay (f a) -> f (ThreeWay a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ThreeWay a -> m (ThreeWay b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ThreeWay a -> f (ThreeWay b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ThreeWay a -> f (ThreeWay b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ThreeWay a -> f (ThreeWay b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
ThreeWay (f a) -> f (ThreeWay a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
ThreeWay (f a) -> f (ThreeWay a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ThreeWay a -> m (ThreeWay b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ThreeWay a -> m (ThreeWay b)
$csequence :: forall (m :: * -> *) a. Monad m => ThreeWay (m a) -> m (ThreeWay a)
sequence :: forall (m :: * -> *) a. Monad m => ThreeWay (m a) -> m (ThreeWay a)
Traversable)

instance Applicative ThreeWay where
  pure :: a -> ThreeWay a
  pure :: forall a. a -> ThreeWay a
pure a
x =
    a -> a -> a -> ThreeWay a
forall a. a -> a -> a -> ThreeWay a
ThreeWay a
x a
x a
x

  (<*>) :: ThreeWay (a -> b) -> ThreeWay a -> ThreeWay b
  ThreeWay a -> b
f a -> b
g a -> b
h <*> :: forall a b. ThreeWay (a -> b) -> ThreeWay a -> ThreeWay b
<*> ThreeWay a
x a
y a
z =
    b -> b -> b -> ThreeWay b
forall a. a -> a -> a -> ThreeWay a
ThreeWay (a -> b
f a
x) (a -> b
g a
y) (a -> b
h a
z)

instance Semialign ThreeWay where
  alignWith :: (These a b -> c) -> ThreeWay a -> ThreeWay b -> ThreeWay c
  alignWith :: forall a b c.
(These a b -> c) -> ThreeWay a -> ThreeWay b -> ThreeWay c
alignWith These a b -> c
f (ThreeWay a
a a
b a
c) (ThreeWay b
x b
y b
z) =
    c -> c -> c -> ThreeWay c
forall a. a -> a -> a -> ThreeWay a
ThreeWay (These a b -> c
f (a -> b -> These a b
forall a b. a -> b -> These a b
These a
a b
x)) (These a b -> c
f (a -> b -> These a b
forall a b. a -> b -> These a b
These a
b b
y)) (These a b -> c
f (a -> b -> These a b
forall a b. a -> b -> These a b
These a
c b
z))

instance Unzip ThreeWay where
  unzipWith :: (c -> (a, b)) -> ThreeWay c -> (ThreeWay a, ThreeWay b)
  unzipWith :: forall c a b.
(c -> (a, b)) -> ThreeWay c -> (ThreeWay a, ThreeWay b)
unzipWith c -> (a, b)
f (ThreeWay c
a c
b c
c) =
    let (a
i, b
x) = c -> (a, b)
f c
a
        (a
j, b
y) = c -> (a, b)
f c
b
        (a
k, b
z) = c -> (a, b)
f c
c
     in (a -> a -> a -> ThreeWay a
forall a. a -> a -> a -> ThreeWay a
ThreeWay a
i a
j a
k, b -> b -> b -> ThreeWay b
forall a. a -> a -> a -> ThreeWay a
ThreeWay b
x b
y b
z)

instance Zip ThreeWay where
  zipWith :: (a -> b -> c) -> ThreeWay a -> ThreeWay b -> ThreeWay c
  zipWith :: forall a b c.
(a -> b -> c) -> ThreeWay a -> ThreeWay b -> ThreeWay c
zipWith a -> b -> c
f (ThreeWay a
a a
b a
c) (ThreeWay b
x b
y b
z) =
    c -> c -> c -> ThreeWay c
forall a. a -> a -> a -> ThreeWay a
ThreeWay (a -> b -> c
f a
a b
x) (a -> b -> c
f a
b b
y) (a -> b -> c
f a
c b
z)

data TwoOrThreeWay a = TwoOrThreeWay
  { forall a. TwoOrThreeWay a -> Maybe a
lca :: Maybe a,
    forall a. TwoOrThreeWay a -> a
alice :: a,
    forall a. TwoOrThreeWay a -> a
bob :: a
  }
  deriving stock ((forall m. Monoid m => TwoOrThreeWay m -> m)
-> (forall m a. Monoid m => (a -> m) -> TwoOrThreeWay a -> m)
-> (forall m a. Monoid m => (a -> m) -> TwoOrThreeWay a -> m)
-> (forall a b. (a -> b -> b) -> b -> TwoOrThreeWay a -> b)
-> (forall a b. (a -> b -> b) -> b -> TwoOrThreeWay a -> b)
-> (forall b a. (b -> a -> b) -> b -> TwoOrThreeWay a -> b)
-> (forall b a. (b -> a -> b) -> b -> TwoOrThreeWay a -> b)
-> (forall a. (a -> a -> a) -> TwoOrThreeWay a -> a)
-> (forall a. (a -> a -> a) -> TwoOrThreeWay a -> a)
-> (forall a. TwoOrThreeWay a -> [a])
-> (forall a. TwoOrThreeWay a -> Bool)
-> (forall a. TwoOrThreeWay a -> Int)
-> (forall a. Eq a => a -> TwoOrThreeWay a -> Bool)
-> (forall a. Ord a => TwoOrThreeWay a -> a)
-> (forall a. Ord a => TwoOrThreeWay a -> a)
-> (forall a. Num a => TwoOrThreeWay a -> a)
-> (forall a. Num a => TwoOrThreeWay a -> a)
-> Foldable TwoOrThreeWay
forall a. Eq a => a -> TwoOrThreeWay a -> Bool
forall a. Num a => TwoOrThreeWay a -> a
forall a. Ord a => TwoOrThreeWay a -> a
forall m. Monoid m => TwoOrThreeWay m -> m
forall a. TwoOrThreeWay a -> Bool
forall a. TwoOrThreeWay a -> Int
forall a. TwoOrThreeWay a -> [a]
forall a. (a -> a -> a) -> TwoOrThreeWay a -> a
forall m a. Monoid m => (a -> m) -> TwoOrThreeWay a -> m
forall b a. (b -> a -> b) -> b -> TwoOrThreeWay a -> b
forall a b. (a -> b -> b) -> b -> TwoOrThreeWay a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => TwoOrThreeWay m -> m
fold :: forall m. Monoid m => TwoOrThreeWay m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> TwoOrThreeWay a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> TwoOrThreeWay a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> TwoOrThreeWay a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> TwoOrThreeWay a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> TwoOrThreeWay a -> b
foldr :: forall a b. (a -> b -> b) -> b -> TwoOrThreeWay a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> TwoOrThreeWay a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> TwoOrThreeWay a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> TwoOrThreeWay a -> b
foldl :: forall b a. (b -> a -> b) -> b -> TwoOrThreeWay a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> TwoOrThreeWay a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> TwoOrThreeWay a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> TwoOrThreeWay a -> a
foldr1 :: forall a. (a -> a -> a) -> TwoOrThreeWay a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> TwoOrThreeWay a -> a
foldl1 :: forall a. (a -> a -> a) -> TwoOrThreeWay a -> a
$ctoList :: forall a. TwoOrThreeWay a -> [a]
toList :: forall a. TwoOrThreeWay a -> [a]
$cnull :: forall a. TwoOrThreeWay a -> Bool
null :: forall a. TwoOrThreeWay a -> Bool
$clength :: forall a. TwoOrThreeWay a -> Int
length :: forall a. TwoOrThreeWay a -> Int
$celem :: forall a. Eq a => a -> TwoOrThreeWay a -> Bool
elem :: forall a. Eq a => a -> TwoOrThreeWay a -> Bool
$cmaximum :: forall a. Ord a => TwoOrThreeWay a -> a
maximum :: forall a. Ord a => TwoOrThreeWay a -> a
$cminimum :: forall a. Ord a => TwoOrThreeWay a -> a
minimum :: forall a. Ord a => TwoOrThreeWay a -> a
$csum :: forall a. Num a => TwoOrThreeWay a -> a
sum :: forall a. Num a => TwoOrThreeWay a -> a
$cproduct :: forall a. Num a => TwoOrThreeWay a -> a
product :: forall a. Num a => TwoOrThreeWay a -> a
Foldable, (forall a b. (a -> b) -> TwoOrThreeWay a -> TwoOrThreeWay b)
-> (forall a b. a -> TwoOrThreeWay b -> TwoOrThreeWay a)
-> Functor TwoOrThreeWay
forall a b. a -> TwoOrThreeWay b -> TwoOrThreeWay a
forall a b. (a -> b) -> TwoOrThreeWay a -> TwoOrThreeWay 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 b. (a -> b) -> TwoOrThreeWay a -> TwoOrThreeWay b
fmap :: forall a b. (a -> b) -> TwoOrThreeWay a -> TwoOrThreeWay b
$c<$ :: forall a b. a -> TwoOrThreeWay b -> TwoOrThreeWay a
<$ :: forall a b. a -> TwoOrThreeWay b -> TwoOrThreeWay a
Functor, (forall x. TwoOrThreeWay a -> Rep (TwoOrThreeWay a) x)
-> (forall x. Rep (TwoOrThreeWay a) x -> TwoOrThreeWay a)
-> Generic (TwoOrThreeWay a)
forall x. Rep (TwoOrThreeWay a) x -> TwoOrThreeWay a
forall x. TwoOrThreeWay a -> Rep (TwoOrThreeWay a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (TwoOrThreeWay a) x -> TwoOrThreeWay a
forall a x. TwoOrThreeWay a -> Rep (TwoOrThreeWay a) x
$cfrom :: forall a x. TwoOrThreeWay a -> Rep (TwoOrThreeWay a) x
from :: forall x. TwoOrThreeWay a -> Rep (TwoOrThreeWay a) x
$cto :: forall a x. Rep (TwoOrThreeWay a) x -> TwoOrThreeWay a
to :: forall x. Rep (TwoOrThreeWay a) x -> TwoOrThreeWay a
Generic, Functor TwoOrThreeWay
Foldable TwoOrThreeWay
(Functor TwoOrThreeWay, Foldable TwoOrThreeWay) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> TwoOrThreeWay a -> f (TwoOrThreeWay b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    TwoOrThreeWay (f a) -> f (TwoOrThreeWay a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> TwoOrThreeWay a -> m (TwoOrThreeWay b))
-> (forall (m :: * -> *) a.
    Monad m =>
    TwoOrThreeWay (m a) -> m (TwoOrThreeWay a))
-> Traversable TwoOrThreeWay
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
TwoOrThreeWay (m a) -> m (TwoOrThreeWay a)
forall (f :: * -> *) a.
Applicative f =>
TwoOrThreeWay (f a) -> f (TwoOrThreeWay a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> TwoOrThreeWay a -> m (TwoOrThreeWay b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> TwoOrThreeWay a -> f (TwoOrThreeWay b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> TwoOrThreeWay a -> f (TwoOrThreeWay b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> TwoOrThreeWay a -> f (TwoOrThreeWay b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
TwoOrThreeWay (f a) -> f (TwoOrThreeWay a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
TwoOrThreeWay (f a) -> f (TwoOrThreeWay a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> TwoOrThreeWay a -> m (TwoOrThreeWay b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> TwoOrThreeWay a -> m (TwoOrThreeWay b)
$csequence :: forall (m :: * -> *) a.
Monad m =>
TwoOrThreeWay (m a) -> m (TwoOrThreeWay a)
sequence :: forall (m :: * -> *) a.
Monad m =>
TwoOrThreeWay (m a) -> m (TwoOrThreeWay a)
Traversable)

instance Applicative TwoOrThreeWay where
  pure :: a -> TwoOrThreeWay a
  pure :: forall a. a -> TwoOrThreeWay a
pure a
x =
    Maybe a -> a -> a -> TwoOrThreeWay a
forall a. Maybe a -> a -> a -> TwoOrThreeWay a
TwoOrThreeWay (a -> Maybe a
forall a. a -> Maybe a
Just a
x) a
x a
x

  (<*>) :: TwoOrThreeWay (a -> b) -> TwoOrThreeWay a -> TwoOrThreeWay b
  TwoOrThreeWay Maybe (a -> b)
f a -> b
g a -> b
h <*> :: forall a b.
TwoOrThreeWay (a -> b) -> TwoOrThreeWay a -> TwoOrThreeWay b
<*> TwoOrThreeWay Maybe a
x a
y a
z =
    Maybe b -> b -> b -> TwoOrThreeWay b
forall a. Maybe a -> a -> a -> TwoOrThreeWay a
TwoOrThreeWay (Maybe (a -> b)
f Maybe (a -> b) -> Maybe a -> Maybe b
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe a
x) (a -> b
g a
y) (a -> b
h a
z)

data TwoWay a = TwoWay
  { forall a. TwoWay a -> a
alice :: a,
    forall a. TwoWay a -> a
bob :: a
  }
  deriving stock ((forall m. Monoid m => TwoWay m -> m)
-> (forall m a. Monoid m => (a -> m) -> TwoWay a -> m)
-> (forall m a. Monoid m => (a -> m) -> TwoWay a -> m)
-> (forall a b. (a -> b -> b) -> b -> TwoWay a -> b)
-> (forall a b. (a -> b -> b) -> b -> TwoWay a -> b)
-> (forall b a. (b -> a -> b) -> b -> TwoWay a -> b)
-> (forall b a. (b -> a -> b) -> b -> TwoWay a -> b)
-> (forall a. (a -> a -> a) -> TwoWay a -> a)
-> (forall a. (a -> a -> a) -> TwoWay a -> a)
-> (forall a. TwoWay a -> [a])
-> (forall a. TwoWay a -> Bool)
-> (forall a. TwoWay a -> Int)
-> (forall a. Eq a => a -> TwoWay a -> Bool)
-> (forall a. Ord a => TwoWay a -> a)
-> (forall a. Ord a => TwoWay a -> a)
-> (forall a. Num a => TwoWay a -> a)
-> (forall a. Num a => TwoWay a -> a)
-> Foldable TwoWay
forall a. Eq a => a -> TwoWay a -> Bool
forall a. Num a => TwoWay a -> a
forall a. Ord a => TwoWay a -> a
forall m. Monoid m => TwoWay m -> m
forall a. TwoWay a -> Bool
forall a. TwoWay a -> Int
forall a. TwoWay a -> [a]
forall a. (a -> a -> a) -> TwoWay a -> a
forall m a. Monoid m => (a -> m) -> TwoWay a -> m
forall b a. (b -> a -> b) -> b -> TwoWay a -> b
forall a b. (a -> b -> b) -> b -> TwoWay a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => TwoWay m -> m
fold :: forall m. Monoid m => TwoWay m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> TwoWay a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> TwoWay a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> TwoWay a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> TwoWay a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> TwoWay a -> b
foldr :: forall a b. (a -> b -> b) -> b -> TwoWay a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> TwoWay a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> TwoWay a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> TwoWay a -> b
foldl :: forall b a. (b -> a -> b) -> b -> TwoWay a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> TwoWay a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> TwoWay a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> TwoWay a -> a
foldr1 :: forall a. (a -> a -> a) -> TwoWay a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> TwoWay a -> a
foldl1 :: forall a. (a -> a -> a) -> TwoWay a -> a
$ctoList :: forall a. TwoWay a -> [a]
toList :: forall a. TwoWay a -> [a]
$cnull :: forall a. TwoWay a -> Bool
null :: forall a. TwoWay a -> Bool
$clength :: forall a. TwoWay a -> Int
length :: forall a. TwoWay a -> Int
$celem :: forall a. Eq a => a -> TwoWay a -> Bool
elem :: forall a. Eq a => a -> TwoWay a -> Bool
$cmaximum :: forall a. Ord a => TwoWay a -> a
maximum :: forall a. Ord a => TwoWay a -> a
$cminimum :: forall a. Ord a => TwoWay a -> a
minimum :: forall a. Ord a => TwoWay a -> a
$csum :: forall a. Num a => TwoWay a -> a
sum :: forall a. Num a => TwoWay a -> a
$cproduct :: forall a. Num a => TwoWay a -> a
product :: forall a. Num a => TwoWay a -> a
Foldable, (forall a b. (a -> b) -> TwoWay a -> TwoWay b)
-> (forall a b. a -> TwoWay b -> TwoWay a) -> Functor TwoWay
forall a b. a -> TwoWay b -> TwoWay a
forall a b. (a -> b) -> TwoWay a -> TwoWay 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 b. (a -> b) -> TwoWay a -> TwoWay b
fmap :: forall a b. (a -> b) -> TwoWay a -> TwoWay b
$c<$ :: forall a b. a -> TwoWay b -> TwoWay a
<$ :: forall a b. a -> TwoWay b -> TwoWay a
Functor, (forall x. TwoWay a -> Rep (TwoWay a) x)
-> (forall x. Rep (TwoWay a) x -> TwoWay a) -> Generic (TwoWay a)
forall x. Rep (TwoWay a) x -> TwoWay a
forall x. TwoWay a -> Rep (TwoWay a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (TwoWay a) x -> TwoWay a
forall a x. TwoWay a -> Rep (TwoWay a) x
$cfrom :: forall a x. TwoWay a -> Rep (TwoWay a) x
from :: forall x. TwoWay a -> Rep (TwoWay a) x
$cto :: forall a x. Rep (TwoWay a) x -> TwoWay a
to :: forall x. Rep (TwoWay a) x -> TwoWay a
Generic, Int -> TwoWay a -> ShowS
[TwoWay a] -> ShowS
TwoWay a -> String
(Int -> TwoWay a -> ShowS)
-> (TwoWay a -> String) -> ([TwoWay a] -> ShowS) -> Show (TwoWay a)
forall a. Show a => Int -> TwoWay a -> ShowS
forall a. Show a => [TwoWay a] -> ShowS
forall a. Show a => TwoWay a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> TwoWay a -> ShowS
showsPrec :: Int -> TwoWay a -> ShowS
$cshow :: forall a. Show a => TwoWay a -> String
show :: TwoWay a -> String
$cshowList :: forall a. Show a => [TwoWay a] -> ShowS
showList :: [TwoWay a] -> ShowS
Show, Functor TwoWay
Foldable TwoWay
(Functor TwoWay, Foldable TwoWay) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> TwoWay a -> f (TwoWay b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    TwoWay (f a) -> f (TwoWay a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> TwoWay a -> m (TwoWay b))
-> (forall (m :: * -> *) a.
    Monad m =>
    TwoWay (m a) -> m (TwoWay a))
-> Traversable TwoWay
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => TwoWay (m a) -> m (TwoWay a)
forall (f :: * -> *) a.
Applicative f =>
TwoWay (f a) -> f (TwoWay a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> TwoWay a -> m (TwoWay b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> TwoWay a -> f (TwoWay b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> TwoWay a -> f (TwoWay b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> TwoWay a -> f (TwoWay b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
TwoWay (f a) -> f (TwoWay a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
TwoWay (f a) -> f (TwoWay a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> TwoWay a -> m (TwoWay b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> TwoWay a -> m (TwoWay b)
$csequence :: forall (m :: * -> *) a. Monad m => TwoWay (m a) -> m (TwoWay a)
sequence :: forall (m :: * -> *) a. Monad m => TwoWay (m a) -> m (TwoWay a)
Traversable)
  deriving anyclass (TwoWay a -> ()
(TwoWay a -> ()) -> NFData (TwoWay a)
forall a. NFData a => TwoWay a -> ()
forall a. (a -> ()) -> NFData a
$crnf :: forall a. NFData a => TwoWay a -> ()
rnf :: TwoWay a -> ()
NFData)
  deriving (Semigroup (TwoWay a)
TwoWay a
Semigroup (TwoWay a) =>
TwoWay a
-> (TwoWay a -> TwoWay a -> TwoWay a)
-> ([TwoWay a] -> TwoWay a)
-> Monoid (TwoWay a)
[TwoWay a] -> TwoWay a
TwoWay a -> TwoWay a -> TwoWay a
forall a.
Semigroup a =>
a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall a. Monoid a => Semigroup (TwoWay a)
forall a. Monoid a => TwoWay a
forall a. Monoid a => [TwoWay a] -> TwoWay a
forall a. Monoid a => TwoWay a -> TwoWay a -> TwoWay a
$cmempty :: forall a. Monoid a => TwoWay a
mempty :: TwoWay a
$cmappend :: forall a. Monoid a => TwoWay a -> TwoWay a -> TwoWay a
mappend :: TwoWay a -> TwoWay a -> TwoWay a
$cmconcat :: forall a. Monoid a => [TwoWay a] -> TwoWay a
mconcat :: [TwoWay a] -> TwoWay a
Monoid, NonEmpty (TwoWay a) -> TwoWay a
TwoWay a -> TwoWay a -> TwoWay a
(TwoWay a -> TwoWay a -> TwoWay a)
-> (NonEmpty (TwoWay a) -> TwoWay a)
-> (forall b. Integral b => b -> TwoWay a -> TwoWay a)
-> Semigroup (TwoWay a)
forall b. Integral b => b -> TwoWay a -> TwoWay a
forall a. Semigroup a => NonEmpty (TwoWay a) -> TwoWay a
forall a. Semigroup a => TwoWay a -> TwoWay a -> TwoWay a
forall a b. (Semigroup a, Integral b) => b -> TwoWay a -> TwoWay a
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
$c<> :: forall a. Semigroup a => TwoWay a -> TwoWay a -> TwoWay a
<> :: TwoWay a -> TwoWay a -> TwoWay a
$csconcat :: forall a. Semigroup a => NonEmpty (TwoWay a) -> TwoWay a
sconcat :: NonEmpty (TwoWay a) -> TwoWay a
$cstimes :: forall a b. (Semigroup a, Integral b) => b -> TwoWay a -> TwoWay a
stimes :: forall b. Integral b => b -> TwoWay a -> TwoWay a
Semigroup) via (GenericSemigroupMonoid (TwoWay a))

instance Applicative TwoWay where
  pure :: forall a. a -> TwoWay a
pure a
x = a -> a -> TwoWay a
forall a. a -> a -> TwoWay a
TwoWay a
x a
x
  TwoWay a -> b
f a -> b
g <*> :: forall a b. TwoWay (a -> b) -> TwoWay a -> TwoWay b
<*> TwoWay a
x a
y = b -> b -> TwoWay b
forall a. a -> a -> TwoWay a
TwoWay (a -> b
f a
x) (a -> b
g a
y)

instance Semialign TwoWay where
  alignWith :: (These a b -> c) -> TwoWay a -> TwoWay b -> TwoWay c
  alignWith :: forall a b c. (These a b -> c) -> TwoWay a -> TwoWay b -> TwoWay c
alignWith These a b -> c
f =
    (a -> b -> c) -> TwoWay a -> TwoWay b -> TwoWay c
forall a b c. (a -> b -> c) -> TwoWay a -> TwoWay b -> TwoWay c
forall (f :: * -> *) a b c.
Zip f =>
(a -> b -> c) -> f a -> f b -> f c
zipWith \a
x b
y -> These a b -> c
f (a -> b -> These a b
forall a b. a -> b -> These a b
These a
x b
y)

instance Unzip TwoWay where
  unzipWith :: (c -> (a, b)) -> TwoWay c -> (TwoWay a, TwoWay b)
  unzipWith :: forall c a b. (c -> (a, b)) -> TwoWay c -> (TwoWay a, TwoWay b)
unzipWith c -> (a, b)
f (TwoWay c
cx c
cy) =
    let (a
ax, b
bx) = c -> (a, b)
f c
cx
        (a
ay, b
by) = c -> (a, b)
f c
cy
     in (a -> a -> TwoWay a
forall a. a -> a -> TwoWay a
TwoWay a
ax a
ay, b -> b -> TwoWay b
forall a. a -> a -> TwoWay a
TwoWay b
bx b
by)

instance Zip TwoWay where
  zipWith :: (a -> b -> c) -> TwoWay a -> TwoWay b -> TwoWay c
  zipWith :: forall a b c. (a -> b -> c) -> TwoWay a -> TwoWay b -> TwoWay c
zipWith a -> b -> c
f (TwoWay a
x1 a
x2) (TwoWay b
y1 b
y2) =
    c -> c -> TwoWay c
forall a. a -> a -> TwoWay a
TwoWay (a -> b -> c
f a
x1 b
y1) (a -> b -> c
f a
x2 b
y2)