How to merge two Consumer into one in Haskell Pipes?

前端 未结 1 814
生来不讨喜
生来不讨喜 2021-02-20 04:31

I use Haskell stream processing library pipes to write a command line tool. Each command line actions may output result to stdout and logs to stderr wi

1条回答
  •  爱一瞬间的悲伤
    2021-02-20 05:07

    (This is @Michael's answer, but I'd like to write it up here so we can move the question out of the unanswered queue for the Haskell tag.)

    See (+++) in pipes-extras. Keep in mind a Consumer is a Pipe (to nowhere), so P.toHandle IO.stderr +++ P.stdoutLn :: MonadIO m => Pipe (Either String String) (Either b d) m ().

    To get a Consumer, you would have to get rid of the Lefts e.g with >-> P.concat or >-> P.drain. There are more robust and handsome ways of doing this with Folds.

    0 讨论(0)
提交回复
热议问题