[英]io-streams partitionEithers
我有工人职能
worker :: a -> Either b c
我想将它应用到流a
和产生的2个流b
和c
,并进一步处理这些流。 例如,我想将c
累积在Map
(本质上是折叠流),然后将b
输出到stderr
。
如何使用io-streams
实现此目标? 看来我不能打电话给connect
两次。 因此,我必须将其放在分区之前,以便分区将以“相反”的方式在OutputStream
上运行:
contrapartitionEithers
:: OutputStream b -> OutputStream c -> IO (OutputStream (Either b c))
它可以实现吗? 如果没有,该怎么办? 如果是,是不是对System.IO.Streams.zip
是“双重”?
System.IO.Streams.zip
:: InputStream a -> InputStream b -> IO (InputStream (a, b))
有时正确的问题包含答案。 因此确实有可能:
contrapartitionEithers
:: OutputStream b -> OutputStream c -> IO (OutputStream (Either b c))
contrapartitionEithers b c = makeOutputStream $ maybe
(writeTo b Nothing >> writeTo c Nothing)
(either (writeTo b . Just) (writeTo c . Just))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.