Gabriella439 / pipes

Compositional pipelines

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Stream Concat with Pipes ?

nhenin opened this issue · comments

Hi, I need to concat a stream on each value produced by an processing upstream... Basically appending a Producer to a Pipe, I'm struggling a bit doing that with Pipes...

Thanks !

commented

You can convert a Producer to a Pipe of the same output type, like this:

import Pipes
import Pipes.Core

producerToPipe :: Monad m => Producer b m r -> Pipe a b m r
producerToPipe producer = closed >\\ producer

... and then once you do so you can sequence the Producer after any Pipe that shares the same output type:

producerAfterPipe :: Monad m => Pipe a b m r -> Producer b m r -> Pipe a b m r
producerAfterPipe pipe producer = do
    pipe
    producerToPipe producer

Thanks !!

commented

@nhenin: You're welcome! 🙂