How to merge two Consumer into one in Haskell Pipes? -
i use haskell stream processing library pipes write command line tool. each command line actions may output result stdout , logs stderr pipes api.
i need consumer has type consumer (either string string) m r print chunk of data (left stderr, right stdout) single consumer.
code wrote (should improved)
this function consumeeither doesn't have flexibility want improve it.
consumeeither :: (monadio m) => consumer (either string string) m () consumeeither = eithers <- await case eithers of (left l) -> (yield l) (liftio . (io.hputstrln io.stderr)) (right r) -> (yiled r) (liftio . putstrln) furthermore useful provide function takes 2 consumers , merge them 1 consumer.
question
does know example or implementation of following interface?
merge :: (monad m) => consumer m r -> consumer b m r -> consumer (either b) m r - 1st argument
stderr - 2nd argument
stdout
usage of function
import pipes import qualified pipes.prelude p import qualified system.io io stdoutorerr :: consumer (either string string) io () stdoutorerr = merge (p.tohandle io.stderr) p.stdoutln thanks
(this @michael's answer, i'd write here can move question out of unanswered queue haskell tag.)
see (+++) in pipes-extras. keep in mind consumer pipe (to nowhere), p.tohandle io.stderr +++ p.stdoutln :: monadio m => pipe (either string string) (either b d) m ().
to consumer, have rid of lefts e.g >-> p.concat or >-> p.drain. there more robust , handsome ways of doing folds.
Comments
Post a Comment