{-# language Safe #-}
module LazyAsync.Actions.Merge where
import LazyAsync.Types (Complex (..), LazyAsync (..), Outcome (..), Status (..))
merge :: ( Status a -> Status b -> Status c )
-> ( LazyAsync a -> LazyAsync b -> LazyAsync c )
merge :: (Status a -> Status b -> Status c)
-> LazyAsync a -> LazyAsync b -> LazyAsync c
merge Status a -> Status b -> Status c
(*) LazyAsync a
a LazyAsync b
b = Complex LazyAsync Status c -> LazyAsync c
forall a. Complex LazyAsync Status a -> LazyAsync a
A2 ((Status a -> Status b -> Status c)
-> LazyAsync a -> LazyAsync b -> Complex LazyAsync Status c
forall (f :: * -> *) (g :: * -> *) a x y.
(g x -> g y -> g a) -> f x -> f y -> Complex f g a
Complex Status a -> Status b -> Status c
(*) LazyAsync a
a LazyAsync b
b)
apply :: LazyAsync (a -> b)
-> LazyAsync a
-> LazyAsync b
apply :: LazyAsync (a -> b) -> LazyAsync a -> LazyAsync b
apply = (Status (a -> b) -> Status a -> Status b)
-> LazyAsync (a -> b) -> LazyAsync a -> LazyAsync b
forall a b c.
(Status a -> Status b -> Status c)
-> LazyAsync a -> LazyAsync b -> LazyAsync c
merge Status (a -> b) -> Status a -> Status b
forall a b. Status (a -> b) -> Status a -> Status b
applyStatus
choose :: LazyAsync a
-> LazyAsync a
-> LazyAsync a
choose :: LazyAsync a -> LazyAsync a -> LazyAsync a
choose = (Status a -> Status a -> Status a)
-> LazyAsync a -> LazyAsync a -> LazyAsync a
forall a b c.
(Status a -> Status b -> Status c)
-> LazyAsync a -> LazyAsync b -> LazyAsync c
merge Status a -> Status a -> Status a
forall a. Status a -> Status a -> Status a
chooseStatus
applyStatus :: Status (a -> b) -> Status a -> Status b
applyStatus :: Status (a -> b) -> Status a -> Status b
applyStatus Status (a -> b)
a Status a
b =
case Status (a -> b)
a of
Done (Success a -> b
f) ->
case Status a
b of
Done (Success a
x) -> Outcome b -> Status b
forall a. Outcome a -> Status a
Done (b -> Outcome b
forall a. a -> Outcome a
Success (a -> b
f a
x))
Done (Failure SomeException
e) -> Outcome b -> Status b
forall a. Outcome a -> Status a
Done (SomeException -> Outcome b
forall a. SomeException -> Outcome a
Failure SomeException
e)
Status a
Incomplete -> Status b
forall a. Status a
Incomplete
Done (Failure SomeException
e) -> Outcome b -> Status b
forall a. Outcome a -> Status a
Done (SomeException -> Outcome b
forall a. SomeException -> Outcome a
Failure SomeException
e)
Status (a -> b)
Incomplete ->
case Status a
b of
Done (Failure SomeException
e) -> Outcome b -> Status b
forall a. Outcome a -> Status a
Done (SomeException -> Outcome b
forall a. SomeException -> Outcome a
Failure SomeException
e)
Status a
_ -> Status b
forall a. Status a
Incomplete
chooseStatus :: Status a -> Status a -> Status a
chooseStatus :: Status a -> Status a -> Status a
chooseStatus Status a
x Status a
y =
case Status a
x of
Done Success{} -> Status a
x
Done Failure{} -> Status a
y
Status a
Incomplete ->
case Status a
y of
Done Failure{} -> Status a
x
Status a
_ -> Status a
y
applyOutcome :: Outcome (a -> b) -> Outcome a -> Outcome b
applyOutcome :: Outcome (a -> b) -> Outcome a -> Outcome b
applyOutcome Outcome (a -> b)
fo Outcome a
ao =
case Outcome (a -> b)
fo of
Failure SomeException
e -> SomeException -> Outcome b
forall a. SomeException -> Outcome a
Failure SomeException
e
Success a -> b
f ->
case Outcome a
ao of
Failure SomeException
e -> SomeException -> Outcome b
forall a. SomeException -> Outcome a
Failure SomeException
e
Success a
x -> b -> Outcome b
forall a. a -> Outcome a
Success (a -> b
f a
x)
chooseOutcome :: Outcome a -> Outcome a -> Outcome a
chooseOutcome :: Outcome a -> Outcome a -> Outcome a
chooseOutcome Outcome a
x Outcome a
y =
case Outcome a
x of
Failure{} -> Outcome a
y
Outcome a
_ -> Outcome a
x