Gabriella439 / pipes

Compositional pipelines
BSD 3-Clause "New" or "Revised" License
487 stars 72 forks source link

Stream Concat with Pipes ? #211

Closed nhenin closed 4 years ago

nhenin commented 4 years ago

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 !

Gabriella439 commented 4 years ago

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
nhenin commented 4 years ago

Thanks !!

Gabriella439 commented 4 years ago

@nhenin: You're welcome! 🙂