这个问题背后的动机是这种情况 - 我们有一个由Sum编码表示的值流。让我们假设Either ByteString ByteString我们分别代表错误和良好状态的字节流。现在,我们有另一个可以压缩ByteString流的函数。是否可以在输入流上运行此函数Either ByteString ByteString,并压缩其中一个(不仅如此,Right而且还可以Left在Left产生而不是 的情况下Right)。compress函数类型签名如下(我使用的是Streaming库):
compress :: MonadIO m
=> Int
-- ^ Compression level.
-> Stream (Of ByteString) m r
-> Stream (Of ByteString) m r
我们的输入流是类型Stream (Of (Either ByteString ByteString)) m r。那么,是否有某种转换器函数可以compress在输入流上运行,并输出一个类型的流,Stream (Of (Either ByteString ByteString)) m r其中两者都被压缩。
在我看来,我应该写一个自定义compress,让我们说eitherCompress如下:
eitherCompress :: MonadIO m
=> Int
-- ^ Compression level.
-> Stream (Of (Either ByteString ByteString)) m r
-> Stream (Of (Either ByteString ByteString)) m r
那是对的吗?如果是这种情况,eitherCompress使用zstd库中的以下函数编写的好方法是什么:
compress :: Int
-- ^ Compression level. Must be >= 1 and <= maxCLevel.
-> IO Result
我已经使用 编写了stream生产者yield,但我已经为输入只是源而不是流的简单情况实现了它们。非常感谢您对这个问题的帮助。