小编ily*_*tre的帖子

如何在Haskell Pipes中将两个Consumer合并为一个?

我使用Haskell流处理库管道来编写命令行工具.每个命令行操作都可以将结果输出stdout到API 并stderr使用pipesAPI 登录.

我需要Consumer哪种类型的Consumer (Either String String) m r打印数据块(Leftto stderr,Rightto stdout)与single Consumer.

我写的代码(应该改进)

这个功能consumeEither没有灵活性,所以我想改进它.

consumeEither :: (MonadIO m) => Consumer (Either String String) m ()
consumeEither = do
  eitherS <- await
  case eitherS of
    (Left l)  -> for (yield l) (liftIO . (IO.hPutStrLn IO.stderr))
    (Right r) -> for (yiled r) (liftIO . putStrLn)
Run Code Online (Sandbox Code Playgroud)

此外,提供一个需要两个Consumer并将它们合并为一个的函数将是有用的Consumer.

题 …

haskell pipe

11
推荐指数
1
解决办法
248
查看次数

标签 统计

haskell ×1

pipe ×1