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
ZSink
is 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
ZTransducer
is a stateful function which processes chunks of data in the stream, and in contrast to aZSink
it's processing never ends.If we look at a trivial example:
We can see that the new
ZStream
encoding is chunk based, and usingtransduce
withutf8Decode
which decodes a chunk of bytes to String and then splits them by line. Finally, we use the.run
method and supply aZSink
which emits data to the console, element by element.More on the new design of ZStream can be found here.