Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(.|) : (Monad m) => PipeM a b r1 m r2 -> PipeM b c r2 m r3 -> PipeM a c r1 m r3
(.|) = pull where
mutual
pull : (Monad m) => PipeM a b r1 m r2 -> PipeM b c r2 m r3 -> PipeM a c r1 m r3
pull up (Yield next c) = Yield (up `pull` next) c -- Yield downstream
pull up (Action a) = lift a >>= \next => up `pull` next -- Produce effect downstream
pull up (Await cont) = up `push` cont -- Ask upstream for a value
pull up (Pure r) = Pure r
push : (Monad m) => PipeM a b r1 m r2 -> (Either r2 b -> PipeM b c r2 m r3) -> PipeM a c r1 m r3
push (Await cont) down = Await (\a => cont a `push` down) -- Await upstream
push (Action a) down = lift a >>= \next => next `push` down -- Produce effect upstream
push (Yield next b) down = next `pull` down (Right b) -- Give back control downstream
push (Pure r) down = Pure r `pull` down (Left r) -- Termination, send pipe result downstream
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment