将源的输出合并为流

问题描述 投票:2回答:1

我想要一个以源为参数的管道,并使用后者的输出结合自己的输出。在类型中,类似于例如

combine :: ConduitM () Int m ()
        -> ConduitM Int (Int, Int) m ()

在哪里,我希望以下

runConduit $ yieldMany [(1::Int)..]
          .| combine (yieldMany [100..])
          .| takeC 5
          .| sinkList

[(1,100), (2,102), (3,103), (4,104), (5, 105)]

这是我的用例的简化版本。但我不确定如何超越这个

combine source = mapC $ \i -> do
  -- stream output from source somehow
  (i, i)

这可能吗?

haskell conduit
1个回答
2
投票

我想你正在寻找ZipSource,在你的情况下看起来像这样:

getZipSource $ (,)
    <$> ZipSource (yieldMany [1..])
    <*> ZipSource (yieldMany [100..])
© www.soinside.com 2019 - 2024. All rights reserved.