module Hydra.Flows where
import Hydra.Kernel
import qualified Hydra.Lib.Flows as Flows
import qualified Control.Monad as CM
import qualified System.IO as IO
fromEither :: Show e => Either e a -> Flow c a
fromEither :: forall e a c. Show e => Either e a -> Flow c a
fromEither Either e a
x = case Either e a
x of
Left e
e -> String -> Flow c a
forall s x. String -> Flow s x
Flows.fail (String -> Flow c a) -> String -> Flow c a
forall a b. (a -> b) -> a -> b
$ e -> String
forall a. Show a => a -> String
show e
e
Right a
a -> a -> Flow c a
forall a. a -> Flow c a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a
fromFlowIo :: s -> Flow s a -> IO.IO a
fromFlowIo :: forall s a. s -> Flow s a -> IO a
fromFlowIo s
cx Flow s a
f = case Maybe a
mv of
Just a
v -> a -> IO a
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return a
v
Maybe a
Nothing -> String -> IO a
forall a. String -> IO a
forall (m :: * -> *) a. MonadFail m => String -> m a
CM.fail (String -> IO a) -> String -> IO a
forall a b. (a -> b) -> a -> b
$ Trace -> String
traceSummary Trace
trace
where
FlowState Maybe a
mv s
_ Trace
trace = Flow s a -> s -> Trace -> FlowState s a
forall s x. Flow s x -> s -> Trace -> FlowState s x
unFlow Flow s a
f s
cx Trace
emptyTrace