How to combine several channels into one or vice versa

Is it possible to combine several channels into one or vice versa?

I struggle with the following functions.

merge :: (Monad m) => [Pipe lioumr] -> Pipe [l] [i] [o] m [r] split :: (Monad m) => Pipe [l] [i] [o] m [r] -> [Pipe lioumr] 
+4
source share
2 answers

From your comment, it looks like you can more easily accomplish what you are trying to do by simply connecting several shells together:

 import Data.Conduit import Data.Serialize.Put (putListOf, putWord32le) import qualified Data.Conduit.Binary as Cb import qualified Data.Conduit.List as Cl import qualified Data.Conduit.Cereal as Cc main :: IO () main = do let source = Cl.sourceList [[1,2,3],[4,5,6],[7,8,9]] encoder = Cc.conduitPut $ putListOf putWord32le runResourceT . runPipe $ source >+> do Cl.isolate 1 >+> encoder >+> Cb.sinkFile "/tmp/1.bin" Cl.isolate 1 >+> encoder >+> Cb.sinkFile "/tmp/2.bin" Cl.isolate 1 >+> encoder >+> Cb.sinkFile "/tmp/3.bin" Cl.sinkNull 
+3
source

As others commented, channel merging has a lot of semantics.

I know that in pipes-core (the fork of the Paolo Capriotti library of Gabriel González pipes , which is another implementation of iterations like conduit ), there is a very common code for monoidal and multiplicative categories.

http://hackage.haskell.org/packages/archive/pipes-core/0.1.0/doc/html/Control-Pipe-Category.html#t:PipeC

For example, using PipeC , a new type that moves type variables around to make PipeC mr valid category, we can multiplex sets of independent signals like Either s.

You also have something like sequence that applies to a Monad instance.

 sequence :: [ma] -> m [a] 

which will alternate different pipes "vertically" (one starts then the next), allowing us to write something like (using Control.Pipe.Pipe from the Gonzalez pipes package)

 takeNPipe :: Int -> Pipe abm [a] takeNPipe n = sequence (replicate n await) 

The type you request implies both of these types of "merge" at the same time. This (I believe) is impossible, since you want to use both parallel (multiplexed) and serial (vertical) composition at the same time.

+1
source

All Articles