I'm studying ZIO Streams, using version 1.0.9 of the library zio-streams.
I cannot find any reference that shows me the difference between a ZSink and a ZTransducer.
What is the difference?
I'm studying ZIO Streams, using version 1.0.9 of the library zio-streams.
I cannot find any reference that shows me the difference between a ZSink and a ZTransducer.
What is the difference?
A
ZSinkis a used to consume elements from theZStream. In turn a sink will cause the materialization of the entire stream to run through and produce a value.A
ZTransduceris a stateful function which processes chunks of data in the stream, and in contrast to aZSinkit's processing never ends.If we look at a trivial example:
We can see that the new
ZStreamencoding is chunk based, and usingtransducewithutf8Decodewhich decodes a chunk of bytes to String and then splits them by line. Finally, we use the.runmethod and supply aZSinkwhich emits data to the console, element by element.More on the new design of ZStream can be found here.