A SubscriptionRef[A]
contains a Ref.Synchronized
with a value of type
A
and a ZStream
that can be subscribed to in order to receive the
current value as well as all changes to the value.
A Take[E, A]
represents a single take
from a queue modeling a stream of
values.
A ZChannel[In, Env, Err, Out, Z]
is a nexus of I/O operations, which supports both reading and
writing.
A ZChannel[In, Env, Err, Out, Z]
is a nexus of I/O operations, which supports both reading and
writing. A channel may read values of type In
and write values of type Out
. When the channel
finishes, it yields a value of type Z
. A channel may fail with a value of type Err
.
Channels are the foundation of ZIO Streams: both streams and sinks are built on channels. Most users shouldn't have to use channels directly, as streams and sinks are much more convenient and cover all common use cases. However, when adding new stream and sink operators, or doing something highly specialized, it may be useful to use channels directly.
Channels compose in a variety of ways:
A ZPipeline[Env, Err, In, Out]
is a polymorphic stream transformer.
A ZPipeline[Env, Err, In, Out]
is a polymorphic stream transformer. Pipelines accept a stream
as input, and return the transformed stream as output.
Pipelines can be thought of as a recipe for calling a bunch of methods on a source stream, to yield a new (transformed) stream. A nice mental model is the following type alias:
type ZPipeline[Env, Err, In, Out] = ZStream[Env, Err, In] => ZStream[Env, Err, Out]
This encoding of a pipeline with a type alias is not used because it does not infer well. In its place, this trait captures the polymorphism inherent to many pipelines, which can therefore be more flexible about the environment and error types of the streams they transform.
There is no fundamental requirement for pipelines to exist, because everything pipelines do can be done directly on a stream. However, because pipelines separate the stream transformation from the source stream itself, it becomes possible to abstract over stream transformations at the level of values, creating, storing, and passing around reusable transformation pipelines that can be applied to many different streams.
The most common way to create a pipeline is to convert a sink into a pipeline (in general, transforming elements of a stream requires the power of a sink). However, the companion object has lots of other pipeline constructors based on the methods of stream.
A
Take[E, A]
represents a singletake
from a queue modeling a stream of values. ATake
may be a failure causeCause[E]
, an chunk valueA
or an end-of-stream marker.