In the code below how can I
change
stdoutCharConsumer
so that it prints a newline after printing all the data from the input streamimplement
mixin
andmixin'
without going into Pipes.Internal? Is it possible? I need someting like the next
function for Producers.
I use Pipes 4.1.0
#!/usr/bin/env runhaskell
{-# OPTIONS_GHC -Wall #-}
import Pipes
digits, characters :: Monad m => Producer Char m ()
digits = each "0123456789"
characters = each "abcdefghijklmnopqrstuvwxyz"
interleave :: Monad m => Producer a m () -> Producer a m () -> Producer a m ()
interleave a b = do
n <- lift $ next a
case n of
Left () -> b
Right (x, a') -> do
yield x
interleave b a'
stdoutCharConsumer :: Consumer Char IO ()
stdoutCharConsumer = await >>= liftIO . putChar >> stdoutCharConsumer
-- first element of the mixin should go first
mixin :: Monad m => Producer b m () -> Pipe a b m ()
mixin = undefined
-- first element of the pipe should go first
mixin' :: Monad m => Producer b m () -> Pipe a b m ()
mixin' = undefined
main :: IO ()
main = do
-- this prints "a0b1c2d3e4f5g6h7i8j9klmnopqrstuvwxyz"
runEffect $ interleave characters digits >-> stdoutCharConsumer
putStrLn ""
-- this prints "0a1b2c3d4e5f6g7h8i9jklmnopqrstuvwxyz"
runEffect $ interleave digits characters >-> stdoutCharConsumer
putStrLn ""
-- should print "0a1b2c3d4e5f6g7h8i9jklmnopqrstuvwxyz"
runEffect $ characters >-> mixin digits >-> stdoutCharConsumer
putStrLn ""
-- should print "a1b2c3d4e5f6g7h8i9jklmnopqrstuvwxyz"
runEffect $ digits >-> mixin characters >-> stdoutCharConsumer
putStrLn ""
-- should print "a1b2c3d4e5f6g7h8i9jklmnopqrstuvwxyz"
runEffect $ characters >-> mixin' digits >-> stdoutCharConsumer
putStrLn ""
-- should print "0a1b2c3d4e5f6g7h8i9jklmnopqrstuvwxyz"
runEffect $ digits >-> mixin' characters >-> stdoutCharConsumer
putStrLn ""
UPD: Now after I read about pull/pushs based streams I think it is impossible even with Pipes.Internal. Is it true?