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!
A limitation of pipes for interprocess communication is that the processes using pipes must have a common parent process (that is, share a common open or initiation process and exist as the result of a fork system call from a parent process).
You can make it do so by using the pipe character '|'. Pipe is used to combine two or more commands, and in this, the output of one command acts as input to another command, and this command's output may act as input to the next command and so on.
In this case, the output of the process and command substitution provided by parallel is being used as arguments to the cp command. We use the tokens “::::” and “:::” since parallel uses what is on the right as a file-argument and argument respectively.
Since Linux 2.6. 11, the pipe capacity is 16 pages (i.e., 65,536 bytes in a system with a page size of 4096 bytes).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With