Can I make a pipe that consumes all of the producer output and passes it on as a list?

haskell

Solution

You can use `Pipes.Prelude.toListM` to collect a `Producer` into a list:

Pipes.Prelude.toListM :: (Monad m) => Producer a m () -> m [a]

Pipes.Prelude.toListM prod :: (Monad m) => m [a]

Then you just feed that list to your `groupConsumer`:

runEffect $ (lift (Pipes.Prelude.toListM prod) >>= yield) >-> groupConsumer

Problem

I'm trying to use the Pipes library to model a workflow. In that workflow, I would like to accumulate all of that output from a producer, and then pass that on. In this case, I know that my producer produces a finite amount of output. So if I have: ``` prod :: Producer a m () accum :: Pipe a [a] m r groupConsumer :: Consumer [a] m r ``` how do I model `accum` so that I can do: ``` runEffect $ prod >-> accum >-> groupConsumer ``` Thanks!

Original source