module Unison.Merge.ThreeWay
  ( ThreeWay (..),
    forgetLca,
    toTwoOrThreeWay,
    toUpdated,
    GThreeWay (..),
    gforgetLca,
    gfromTwoWay,
    gtoUpdated,
  )
where

import Unison.Merge.Internal.Types (GThreeWay (..), ThreeWay (..))
import Unison.Merge.TwoOrThreeWay (TwoOrThreeWay (..))
import Unison.Merge.TwoWay (TwoWay (..))
import Unison.Merge.Updated (GUpdated (..), Updated)

forgetLca :: ThreeWay a -> TwoWay a
forgetLca :: forall a. ThreeWay a -> TwoWay a
forgetLca ThreeWay {a
alice :: a
$sel:alice:ThreeWay :: forall a. ThreeWay a -> a
alice, a
bob :: a
$sel:bob:ThreeWay :: forall a. ThreeWay a -> a
bob} =
  TwoWay {a
alice :: a
$sel:alice:TwoWay :: a
alice, a
bob :: a
$sel:bob:TwoWay :: a
bob}

toTwoOrThreeWay :: ThreeWay a -> TwoOrThreeWay a
toTwoOrThreeWay :: forall a. ThreeWay a -> TwoOrThreeWay a
toTwoOrThreeWay ThreeWay {a
$sel:alice:ThreeWay :: forall a. ThreeWay a -> a
alice :: a
alice, a
$sel:bob:ThreeWay :: forall a. ThreeWay a -> a
bob :: a
bob, a
lca :: a
$sel:lca:ThreeWay :: forall a. ThreeWay a -> a
lca} =
  TwoOrThreeWay {a
alice :: a
$sel:alice:TwoOrThreeWay :: a
alice, a
bob :: a
$sel:bob:TwoOrThreeWay :: a
bob, $sel:lca:TwoOrThreeWay :: Maybe a
lca = a -> Maybe a
forall a. a -> Maybe a
Just a
lca}

toUpdated :: ThreeWay a -> TwoWay (Updated a)
toUpdated :: forall a. ThreeWay a -> TwoWay (Updated a)
toUpdated =
  GThreeWay a a -> TwoWay (GUpdated a a)
forall a b. GThreeWay a b -> TwoWay (GUpdated a b)
gtoUpdated (GThreeWay a a -> TwoWay (GUpdated a a))
-> (ThreeWay a -> GThreeWay a a)
-> ThreeWay a
-> TwoWay (GUpdated a a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ThreeWay a -> GThreeWay a a
forall a. ThreeWay a -> GThreeWay a a
toG

toG :: ThreeWay a -> GThreeWay a a
toG :: forall a. ThreeWay a -> GThreeWay a a
toG ThreeWay {a
$sel:lca:ThreeWay :: forall a. ThreeWay a -> a
lca :: a
lca, a
$sel:alice:ThreeWay :: forall a. ThreeWay a -> a
alice :: a
alice, a
$sel:bob:ThreeWay :: forall a. ThreeWay a -> a
bob :: a
bob} =
  GThreeWay {a
lca :: a
$sel:lca:GThreeWay :: a
lca, a
alice :: a
$sel:alice:GThreeWay :: a
alice, a
bob :: a
$sel:bob:GThreeWay :: a
bob}

gforgetLca :: GThreeWay a b -> TwoWay b
gforgetLca :: forall a b. GThreeWay a b -> TwoWay b
gforgetLca GThreeWay {b
$sel:alice:GThreeWay :: forall a b. GThreeWay a b -> b
alice :: b
alice, b
$sel:bob:GThreeWay :: forall a b. GThreeWay a b -> b
bob :: b
bob} =
  TwoWay {b
$sel:alice:TwoWay :: b
alice :: b
alice, b
$sel:bob:TwoWay :: b
bob :: b
bob}

gfromTwoWay :: a -> TwoWay b -> GThreeWay a b
gfromTwoWay :: forall a b. a -> TwoWay b -> GThreeWay a b
gfromTwoWay a
lca TwoWay {b
$sel:alice:TwoWay :: forall a. TwoWay a -> a
alice :: b
alice, b
$sel:bob:TwoWay :: forall a. TwoWay a -> a
bob :: b
bob} =
  GThreeWay {a
$sel:lca:GThreeWay :: a
lca :: a
lca, b
$sel:alice:GThreeWay :: b
alice :: b
alice, b
$sel:bob:GThreeWay :: b
bob :: b
bob}

gtoUpdated :: GThreeWay a b -> TwoWay (GUpdated a b)
gtoUpdated :: forall a b. GThreeWay a b -> TwoWay (GUpdated a b)
gtoUpdated GThreeWay {a
$sel:lca:GThreeWay :: forall a b. GThreeWay a b -> a
lca :: a
lca, b
$sel:alice:GThreeWay :: forall a b. GThreeWay a b -> b
alice :: b
alice, b
$sel:bob:GThreeWay :: forall a b. GThreeWay a b -> b
bob :: b
bob} =
  TwoWay
    { $sel:alice:TwoWay :: GUpdated a b
alice = Updated {$sel:old:Updated :: a
old = a
lca, $sel:new:Updated :: b
new = b
alice},
      $sel:bob:TwoWay :: GUpdated a b
bob = Updated {$sel:old:Updated :: a
old = a
lca, $sel:new:Updated :: b
new = b
bob}
    }