The motivation behind this question is this scenario - we have a stream of values which are represented by a Sum encoding. Let us assume Either ByteString ByteString where we represent streams of bytes in error and good states respectively. Now, we have another function which can compress the ByteString stream. Is it possible to run this function on Either ByteString ByteString input stream, and compress either one (not just Right but also Left in case Left is yielded instead of Right). A compress function type signature is below (I am using Streaming library):
compress :: MonadIO m
=> Int
-- ^ Compression level.
-> Stream (Of ByteString) m r
-> Stream (Of ByteString) m r
Our input stream is of type Stream (Of (Either ByteString ByteString)) m r. So, is there some kind of transformer function that can run compress on input stream, and output a stream of type Stream (Of (Either ByteString ByteString)) m r where both are compressed.
It seems to me that I should write a custom compress instead, let us say eitherCompress as follows:
eitherCompress :: MonadIO m
=> Int
-- ^ Compression level.
-> Stream (Of (Either ByteString ByteString)) m r
-> Stream (Of (Either ByteString ByteString)) m r
Is that correct? If that is the case, what is a good way to write eitherCompress using the function below from zstd library:
compress :: Int
-- ^ Compression level. Must be >= 1 and <= maxCLevel.
-> IO Result
I have written stream producers using yield, but I have implemented them for simple cases where the input is just a source, not a stream. Will very much appreciate help with this problem.