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.
- Companion:
- object
Value members
Concrete methods
Composes two pipelines into one pipeline, by first applying the transformation of the specified pipeline, and then applying the transformation of this pipeline.
Composes two pipelines into one pipeline, by first applying the transformation of the specified pipeline, and then applying the transformation of this pipeline.
Composes two pipelines into one pipeline, by first applying the transformation of this pipeline, and then applying the transformation of the specified pipeline.
Composes two pipelines into one pipeline, by first applying the transformation of this pipeline, and then applying the transformation of the specified pipeline.
Compose this transducer with a sink, resulting in a sink that processes elements by piping them through this transducer and piping the results into the sink.
Compose this transducer with a sink, resulting in a sink that processes elements by piping them through this transducer and piping the results into the sink.
Aggregates elements of this stream using the provided sink for as long as the downstream operators on the stream are busy.
Aggregates elements of this stream using the provided sink for as long as the downstream operators on the stream are busy.
This operator divides the stream into two asynchronous "islands". Operators upstream of this operator run on one fiber, while downstream operators run on another. Whenever the downstream fiber is busy processing elements, the upstream fiber will feed elements into the sink until it signals completion.
Any sink can be used here, but see ZSink.foldWeightedZIO and ZSink.foldUntilZIO for sinks that cover the common usecases.
Like aggregateAsyncWithinEither
, but only returns the Right
results.
Like aggregateAsyncWithinEither
, but only returns the Right
results.
Aggregates elements using the provided sink until it completes, or until the delay signalled by the schedule has passed.
Aggregates elements using the provided sink until it completes, or until the delay signalled by the schedule has passed.
This operator divides the stream into two asynchronous islands. Operators upstream of this operator run on one fiber, while downstream operators run on another. Elements will be aggregated by the sink until the downstream fiber pulls the aggregated value, or until the schedule's delay has passed.
Aggregated elements will be fed into the schedule to determine the delays between pulls.
Returns a new pipeline that only emits elements that are not equal to the previous element emitted, using natural equality to determine whether two elements are equal.
Returns a new pipeline that only emits elements that are not equal to the previous element emitted, using natural equality to determine whether two elements are equal.
Returns a new pipeline that only emits elements that are not equal to the previous element emitted, using the specified function to determine whether two elements are equal.
Returns a new pipeline that only emits elements that are not equal to the previous element emitted, using the specified function to determine whether two elements are equal.
Returns a new pipeline that only emits elements that are not equal to the previous element emitted, using the specified effectual function to determine whether two elements are equal.
Returns a new pipeline that only emits elements that are not equal to the previous element emitted, using the specified effectual function to determine whether two elements are equal.
Exposes the underlying chunks of the stream as a stream of chunks of elements.
Exposes the underlying chunks of the stream as a stream of chunks of elements.
Filters any 'None' values.
Filters any 'None' values.
Filters any Exit.Failure
values.
Filters any Exit.Failure
values.
Transforms all elements of the pipeline for as long as the specified partial function is defined.
Transforms all elements of the pipeline for as long as the specified partial function is defined.
Terminates the pipeline when encountering the first Right
.
Terminates the pipeline when encountering the first Right
.
Terminates the pipeline when encountering the first Left
.
Terminates the pipeline when encountering the first Left
.
Terminates the pipeline when encountering the first None
.
Terminates the pipeline when encountering the first None
.
Terminates the pipeline when encountering the first Exit.Failure
.
Terminates the pipeline when encountering the first Exit.Failure
.
Effectfully transforms all elements of the pipeline for as long as the specified partial function is defined.
Effectfully transforms all elements of the pipeline for as long as the specified partial function is defined.
Converts this pipeline to a pipeline that executes its effects but emits no elements. Useful for sequencing effects using pipeline:
Converts this pipeline to a pipeline that executes its effects but emits no elements. Useful for sequencing effects using pipeline:
(Stream(1, 2, 3).tap(i => ZIO(println(i))) ++
(Stream.fromZIO(ZIO(println("Done!"))) >>> ZPipeline.drain) ++
Stream(4, 5, 6).tap(i => ZIO(println(i)))).run(Sink.drain)
Drops the specified number of elements from this stream.
Drops the specified number of elements from this stream.
Drops the last specified number of elements from this pipeline.
Drops the last specified number of elements from this pipeline.
- Note:
This combinator keeps
n
elements in memory. Be careful with big numbers.
Drops all elements of the pipeline until the specified predicate evaluates
to true
.
Drops all elements of the pipeline until the specified predicate evaluates
to true
.
Drops incoming elements until the effectful predicate p
is satisfied.
Drops incoming elements until the effectful predicate p
is satisfied.
Drops all elements of the pipeline for as long as the specified predicate
evaluates to true
.
Drops all elements of the pipeline for as long as the specified predicate
evaluates to true
.
Drops incoming elements as long as the effectful predicate p
is
satisfied.
Drops incoming elements as long as the effectful predicate p
is
satisfied.
Filters the elements emitted by this pipeline using the provided function.
Filters the elements emitted by this pipeline using the provided function.
Effectfully filters the elements emitted by this pipeline.
Effectfully filters the elements emitted by this pipeline.
Submerges the chunks carried by this pipeline into the pipeline's structure, while still preserving them.
Submerges the chunks carried by this pipeline into the pipeline's structure, while still preserving them.
Submerges the iterables carried by this pipeline into the pipeline's structure, while still preserving them.
Submerges the iterables carried by this pipeline into the pipeline's structure, while still preserving them.
Partitions the pipeline with specified chunkSize
Partitions the pipeline with specified chunkSize
- Value parameters:
- chunkSize
size of the chunk
Partitions the stream with the specified chunkSize or until the specified duration has passed, whichever is satisfied first.
Partitions the stream with the specified chunkSize or until the specified duration has passed, whichever is satisfied first.
Intersperse pipeline with provided element similar to
List.mkString
.
Intersperse pipeline with provided element similar to
List.mkString
.
Intersperse and also add a prefix and a suffix
Intersperse and also add a prefix and a suffix
Transforms the elements of this pipeline using the supplied function.
Transforms the elements of this pipeline using the supplied function.
Statefully maps over the elements of this pipeline to produce new elements.
Statefully maps over the elements of this pipeline to produce new elements.
Statefully and effectfully maps over the elements of this pipeline to produce new elements.
Statefully and effectfully maps over the elements of this pipeline to produce new elements.
Creates a pipeline that maps chunks of elements with the specified effect.
Creates a pipeline that maps chunks of elements with the specified effect.
Transforms the errors emitted by this pipeline using f
.
Transforms the errors emitted by this pipeline using f
.
Creates a pipeline that maps elements with the specified function that returns a stream.
Creates a pipeline that maps elements with the specified function that returns a stream.
Creates a pipeline that maps elements with the specified effectful function.
Creates a pipeline that maps elements with the specified effectful function.
Translates pipeline failure into death of the fiber, making all failures unchecked and not a part of the type of the effect.
Translates pipeline failure into death of the fiber, making all failures unchecked and not a part of the type of the effect.
Keeps none of the errors, and terminates the fiber with them, using the
specified function to convert the E
into a Throwable
.
Keeps none of the errors, and terminates the fiber with them, using the
specified function to convert the E
into a Throwable
.
Takes the specified number of elements from this pipeline.
Takes the specified number of elements from this pipeline.
Takes all elements of the pipeline until the specified predicate evaluates
to true
.
Takes all elements of the pipeline until the specified predicate evaluates
to true
.
Takes all elements of the pipeline for as long as the specified predicate
evaluates to true
.
Takes all elements of the pipeline for as long as the specified predicate
evaluates to true
.
Adds an effect to consumption of every element of the pipeline.
Adds an effect to consumption of every element of the pipeline.
Throttles the chunks of this pipeline according to the given bandwidth
parameters using the token bucket algorithm. Allows for burst in the
processing of elements by allowing the token bucket to accumulate tokens up
to a units + burst
threshold. Chunks that do not meet the bandwidth
constraints are dropped. The weight of each chunk is determined by the
costFn
function.
Throttles the chunks of this pipeline according to the given bandwidth
parameters using the token bucket algorithm. Allows for burst in the
processing of elements by allowing the token bucket to accumulate tokens up
to a units + burst
threshold. Chunks that do not meet the bandwidth
constraints are dropped. The weight of each chunk is determined by the
costFn
function.
Throttles the chunks of this pipeline according to the given bandwidth
parameters using the token bucket algorithm. Allows for burst in the
processing of elements by allowing the token bucket to accumulate tokens up
to a units + burst
threshold. Chunks that do not meet the bandwidth
constraints are dropped. The weight of each chunk is determined by the
costFn
effectful function.
Throttles the chunks of this pipeline according to the given bandwidth
parameters using the token bucket algorithm. Allows for burst in the
processing of elements by allowing the token bucket to accumulate tokens up
to a units + burst
threshold. Chunks that do not meet the bandwidth
constraints are dropped. The weight of each chunk is determined by the
costFn
effectful function.
Delays the chunks of this pipeline according to the given bandwidth
parameters using the token bucket algorithm. Allows for burst in the
processing of elements by allowing the token bucket to accumulate tokens up
to a units + burst
threshold. The weight of each chunk is determined by
the costFn
function.
Delays the chunks of this pipeline according to the given bandwidth
parameters using the token bucket algorithm. Allows for burst in the
processing of elements by allowing the token bucket to accumulate tokens up
to a units + burst
threshold. The weight of each chunk is determined by
the costFn
function.
Delays the chunks of this pipeline according to the given bandwidth
parameters using the token bucket algorithm. Allows for burst in the
processing of elements by allowing the token bucket to accumulate tokens up
to a units + burst
threshold. The weight of each chunk is determined by
the costFn
effectful function.
Delays the chunks of this pipeline according to the given bandwidth
parameters using the token bucket algorithm. Allows for burst in the
processing of elements by allowing the token bucket to accumulate tokens up
to a units + burst
threshold. The weight of each chunk is determined by
the costFn
effectful function.
Zips this pipeline together with the index of elements.
Zips this pipeline together with the index of elements.