module Unison.Merge.EitherWay
  ( EitherWay (..),
    swap,
    value,
  )
where

-- | Alice exclusive-or Bob?
data EitherWay a
  = Alice a
  | Bob a
  deriving stock (EitherWay a -> EitherWay a -> Bool
(EitherWay a -> EitherWay a -> Bool)
-> (EitherWay a -> EitherWay a -> Bool) -> Eq (EitherWay a)
forall a. Eq a => EitherWay a -> EitherWay a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => EitherWay a -> EitherWay a -> Bool
== :: EitherWay a -> EitherWay a -> Bool
$c/= :: forall a. Eq a => EitherWay a -> EitherWay a -> Bool
/= :: EitherWay a -> EitherWay a -> Bool
Eq, (forall a b. (a -> b) -> EitherWay a -> EitherWay b)
-> (forall a b. a -> EitherWay b -> EitherWay a)
-> Functor EitherWay
forall a b. a -> EitherWay b -> EitherWay a
forall a b. (a -> b) -> EitherWay a -> EitherWay 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) -> EitherWay a -> EitherWay b
fmap :: forall a b. (a -> b) -> EitherWay a -> EitherWay b
$c<$ :: forall a b. a -> EitherWay b -> EitherWay a
<$ :: forall a b. a -> EitherWay b -> EitherWay a
Functor, Int -> EitherWay a -> ShowS
[EitherWay a] -> ShowS
EitherWay a -> String
(Int -> EitherWay a -> ShowS)
-> (EitherWay a -> String)
-> ([EitherWay a] -> ShowS)
-> Show (EitherWay a)
forall a. Show a => Int -> EitherWay a -> ShowS
forall a. Show a => [EitherWay a] -> ShowS
forall a. Show a => EitherWay a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> EitherWay a -> ShowS
showsPrec :: Int -> EitherWay a -> ShowS
$cshow :: forall a. Show a => EitherWay a -> String
show :: EitherWay a -> String
$cshowList :: forall a. Show a => [EitherWay a] -> ShowS
showList :: [EitherWay a] -> ShowS
Show)

swap :: EitherWay a -> EitherWay a
swap :: forall a. EitherWay a -> EitherWay a
swap = \case
  Alice a
x -> a -> EitherWay a
forall a. a -> EitherWay a
Bob a
x
  Bob a
x -> a -> EitherWay a
forall a. a -> EitherWay a
Alice a
x

value :: EitherWay a -> a
value :: forall a. EitherWay a -> a
value = \case
  Alice a
x -> a
x
  Bob a
x -> a
x