It just occurred to me, for what it's worth, that this problem is easily 
solved using the `chunksOf` 
from the still clumsy `Streaming.Pipes` module 
https://github.com/michaelt/streaming-utils/blob/master/Streaming/Pipes.hs#L341

Then you can use one of the functor-general zipping functions from the 
`Streaming` module e.g.

   zips :: (Monad m, Functor f, Functor g) => Stream f m r -> Stream g m r 
-> Stream (Compose f g) m r
   zipsWith:: (Monad m, Functor h) => (forall x y. f x -> g y -> h (x, y)) -> 
Stream f m r -> Stream g m r -> Stream h m r

Of course these zips could as well be implemented in 
`Control.Monad.Trans.Free`.  Then you just write something that in 
Data.List style would
look like, say, `mapM_ action $ zip filepaths $ chunksOf n producer`

 

>     module Main (main) where
>
>     import Pipes
>     import qualified Pipes.Prelude as P
>     import Streaming 
>     import qualified Streaming.Prelude as S
>     import qualified Streaming.Pipes as SP
>     import qualified System.IO as IO 
>
>     main = run $ maps action $ zips filepaths $ SP.chunksOf 2 $ 
> text_producer 3
>       where
>
>       text_producer :: Int -> Producer String IO ()
>       text_producer n = P.stdinLn >-> P.take n
>
>       filepaths :: Stream (Of FilePath) IO ()
>       filepaths =  S.each $ map (\n -> show n ++ ".txt") [1..] -- 
> ["1.txt","2.txt"..]
>
>       action :: Compose (Of FilePath) (Producer String IO) r -> IO r
>       action (Compose (file :> p)) = IO.withFile file IO.WriteMode $ \h ->
>                runEffect $ p >-> P.toHandle h
>



     -- >>> main
     -- hello<Enter> 
     -- world<Enter> 
     -- goodbye<Enter> 
     -- >>> :! cat 1.txt
     -- hello
     -- world
     -- >>> :! cat 2.txt 

    -- goodbye

    -- >>> 

-- 
You received this message because you are subscribed to the Google Groups 
"Haskell Pipes" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to haskell-pipes+unsubscr...@googlegroups.com.
To post to this group, send email to haskell-pipes@googlegroups.com.

Reply via email to