Operator alias for zipRight
Composes this stream with the specified stream to create a cartesian product of elements
and keeps only the elements from the that
stream.
Composes this stream with the specified stream to create a cartesian product of elements
and keeps only the elements from the that
stream. The that
stream would be run multiple
times, for every element in the this
stream.
See also ZStream#zipWith and ZStream#<&> for the more common point-wise variant.
Concatenates with another stream in strict order
Operator alias for zipLeft
Operator alias for zip
Composes this stream with the specified stream to create a cartesian product of elements
and keeps only the elements from the this
stream.
Composes this stream with the specified stream to create a cartesian product of elements
and keeps only the elements from the this
stream. The that
stream would be run multiple
times, for every element in the this
stream.
See also ZStream#zipWith and ZStream#<&> for the more common point-wise variant.
Composes this stream with the specified stream to create a cartesian product of elements.
Composes this stream with the specified stream to create a cartesian product of elements.
The that
stream would be run multiple times, for every element in the this
stream.
See also ZStream#zip and ZStream#<&> for the more common point-wise variant.
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 Sink.foldWeightedM and Sink.foldUntilM for sinks that cover the common usecases.
Uses aggregateWithinEither
but only returns the Right
results.
Uses aggregateWithinEither
but only returns the Right
results.
environment type
error type
type of the values consumed by the given sink
type of the value produced by the given sink and consumed by the given schedule
type of the value produced by the given schedule
used for the aggregation
signalling for when to stop the aggregation
ZStream[R1 with Clock, E1, B]
Aggregates elements using the provided sink until it signals completion, or the delay signalled by the schedule has passed.
Aggregates elements using the provided sink until it signals completion, or 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.
environment type
error type
type of the values consumed by the given sink
type of the value produced by the given sink and consumed by the given schedule
type of the value produced by the given schedule
used for the aggregation
signalling for when to stop the aggregation
ZStream[R1 with Clock, E1, Either[C, B]]
Maps the success values of this stream to the specified constant value.
Returns a stream whose failure and success channels have been mapped by
the specified pair of functions, f
and g
.
Fan out the stream, producing a list of streams that have the same elements as this stream.
Fan out the stream, producing a list of streams that have the same elements as this stream. The driver streamer will only ever advance of the maximumLag values before the slowest downstream stream.
Converts the stream to a managed list of queues.
Converts the stream to a managed list of queues. Every value will be replicated to every queue with the slowest queue being allowed to buffer maximumLag elements before the driver is backpressured. The downstream queues will be provided with elements in the same order they are returned, so the fastest queue might have seen up to (maximumLag + 1) elements more than the slowest queue if it has a lower index than the slowest queue. During the finalizer the driver will wait for all queues to shutdown in order to signal completion. After the managed value is used, the queues will never again produce values and should be discarded.
Allows a faster producer to progress independently of a slower consumer by buffering
up to capacity
elements in a queue.
Allows a faster producer to progress independently of a slower consumer by buffering
up to capacity
elements in a queue.
Prefer capacities that are powers of 2 for better performance.
Switches over to the stream produced by the provided function in case this one fails with a typed error.
Switches over to the stream produced by the provided function in case this one fails.
Switches over to the stream produced by the provided function in case this one fails. Allows recovery from all errors, except external interruption.
Performs a filter and map in a single step.
Transforms all elements of the stream for as long as the specified partial function is defined.
Combines this stream and the specified stream by repeatedly applying the
function f0
to extract an element from the queues and conceptually "offer"
it to the destination stream.
Combines this stream and the specified stream by repeatedly applying the
function f0
to extract an element from the queues and conceptually "offer"
it to the destination stream. f0
can maintain some internal state to control
the combining process, with the initial state being specified by s1
.
Appends another stream to this stream.
Appends another stream to this stream. The concatenated stream will first emit the
elements of this stream, and then emit the elements of the other
stream.
Composes this stream with the specified stream to create a cartesian product of elements.
Composes this stream with the specified stream to create a cartesian product of elements.
The that
stream would be run multiple times, for every element in the this
stream.
See also ZStream#zip and ZStream#<&> for the more common point-wise variant.
Composes this stream with the specified stream to create a cartesian product of elements with a specified function.
Composes this stream with the specified stream to create a cartesian product of elements
with a specified function.
The that
stream would be run multiple times, for every element in the this
stream.
See also ZStream#zip and ZStream#<&> for the more common point-wise variant.
More powerful version of ZStream#distributedWith
.
More powerful version of ZStream#distributedWith
. This returns a function that will produce
new queues and corresponding indices.
You can also provide a function that will be executed after the final events are enqueued in all queues
but before the queues are actually shutdown.
Shutdown of the queues is handled by the driver.
Downstream users can also shutdown queues manually. In this case the driver will
continue but no longer backpressure on them.
More powerful version of ZStream#broadcast
.
More powerful version of ZStream#broadcast
. Allows to provide a function that determines what
queues should receive which elements.
Converts this stream to a stream that executes its effects but emits no elements.
Converts this stream to a stream that executes its effects but emits no elements. Useful for sequencing effects using streams:
(Stream(1, 2, 3).tap(i => ZIO(println(i))) ++ Stream.lift(ZIO(println("Done!"))).drain ++ Stream(4, 5, 6).tap(i => ZIO(println(i)))).run(Sink.drain)
Drops the specified number of elements from this stream.
Drops all elements of the stream until the specified predicate evaluates
to true
.
Drops all elements of the stream for as long as the specified predicate
evaluates to true
.
Returns a stream whose failures and successes have been lifted into an
Either
.
Returns a stream whose failures and successes have been lifted into an
Either
. The resulting stream cannot fail, because the failures have
been exposed as part of the Either
success case.
the stream will end as soon as the first error occurs.
Executes the provided finalizer after this stream's finalizers run.
Executes the provided finalizer before this stream's finalizers run.
Filters this stream by the specified predicate, retaining all elements for which the predicate evaluates to true.
Filters this stream by the specified effectful predicate, retaining all elements for which the predicate evaluates to true.
Filters this stream by the specified predicate, removing all elements for which the predicate evaluates to true.
Emits elements of this stream with a fixed delay in between, regardless of how long it takes to produce a value.
Returns a stream made of the concatenation in strict order of all the streams
produced by passing each element of this stream to f0
Maps each element of this stream to another stream and returns the
non-deterministic merge of those streams, executing up to n
inner streams
concurrently.
Maps each element of this stream to another stream and returns the
non-deterministic merge of those streams, executing up to n
inner streams
concurrently. Up to outputBuffer
elements of the produced streams may be
buffered in memory by this operator.
Maps each element of this stream to another stream and returns the non-deterministic merge
of those streams, executing up to n
inner streams concurrently.
Maps each element of this stream to another stream and returns the non-deterministic merge
of those streams, executing up to n
inner streams concurrently. When a new stream is created
from an element of the source stream, the oldest executing stream is cancelled. Up to bufferSize
elements of the produced streams may be buffered in memory by this operator.
Executes a pure fold over the stream of values - reduces all elements in the stream to a value of type S
.
Executes an effectful fold over the stream of values.
Executes an pure fold over the stream of values.
Executes an pure fold over the stream of values. Returns a Managed value that represents the scope of the stream.
Executes an effectful fold over the stream of values.
Executes an effectful fold over the stream of values. Returns a Managed value that represents the scope of the stream.
Reduces the elements in the stream to a value of type S
.
Reduces the elements in the stream to a value of type S
.
Stops the fold early when the condition is not fulfilled.
Executes an effectful fold over the stream of values.
Executes an effectful fold over the stream of values. Stops the fold early when the condition is not fulfilled. Example:
Stream(1) .forever // an infinite Stream of 1's .fold(0)(_ <= 4)((s, a) => UIO(s + a)) // UIO[Int] == 5
function which defines the early termination condition
Executes an pure fold over the stream of values.
Executes an pure fold over the stream of values. Returns a Managed value that represents the scope of the stream. Stops the fold early when the condition is not fulfilled.
Executes an effectful fold over the stream of values.
Executes an effectful fold over the stream of values. Returns a Managed value that represents the scope of the stream. Stops the fold early when the condition is not fulfilled. Example:
Stream(1) .forever // an infinite Stream of 1's .fold(0)(_ <= 4)((s, a) => UIO(s + a)) // Managed[Nothing, Int] .use(ZIO.succeed) // UIO[Int] == 5
function which defines the early termination condition
Consumes all elements of the stream, passing them to the specified callback.
Like ZStream#foreach, but returns a ZManaged
so the finalization order
can be controlled.
Consumes elements of the stream, passing them to the specified callback,
and terminating consumption when the callback returns false
.
Like ZStream#foreachWhile, but returns a ZManaged
so the finalization order
can be controlled.
Repeats this stream forever.
More powerful version of ZStream#groupByKey
Group a stream using a function.
Interleaves this stream and the specified stream deterministically by alternating pulling values from this stream and the specified stream.
Interleaves this stream and the specified stream deterministically by alternating pulling values from this stream and the specified stream. When one stream is exhausted all remaining values in the other stream will be pulled.
Combines this stream and the specified stream deterministically using the
stream of boolean values b
to control which stream to pull from next.
Combines this stream and the specified stream deterministically using the
stream of boolean values b
to control which stream to pull from next.
true
indicates to pull from this stream and false
indicates to pull
from the specified stream. Only consumes as many elements as requested by
b
. If either this stream or the specified stream are exhausted further
requests for values from that stream will be ignored.
Enqueues elements of this stream into a queue.
Enqueues elements of this stream into a queue. Stream failure and ending will also be signalled.
Like ZStream#into, but provides the result as a ZManaged to allow for scope composition.
Returns a stream made of the elements of this stream transformed with f0
Statefully maps over the elements of this stream to produce new elements.
Statefully and effectfully maps over the elements of this stream to produce new elements.
Maps each element to a chunk, and flattens the chunks into the output of this stream.
Effectfully maps each element to a chunk, and flattens the chunks into the output of this stream.
Transforms the errors that possibly result from this stream.
Transforms the errors that possibly result from this stream.
Maps over elements of the stream with the specified effectful function.
Maps over elements of the stream with the specified effectful function,
executing up to n
invocations of f
concurrently.
Maps over elements of the stream with the specified effectful function,
executing up to n
invocations of f
concurrently. Transformed elements
will be emitted in the original order.
Maps over elements of the stream with the specified effectful function,
executing up to n
invocations of f
concurrently.
Maps over elements of the stream with the specified effectful function,
executing up to n
invocations of f
concurrently. The element order
is not enforced by this combinator, and elements may be reordered.
Merges this stream and the specified stream together.
Merges this stream and the specified stream together to produce a stream of eithers.
Merges this stream and the specified stream together to a common element type with the specified mapping functions.
Switches to the provided stream in case this one fails with a typed error.
Switches to the provided stream in case this one fails with a typed error.
See also ZStream#catchAll.
Partition a stream using a predicate.
Partition a stream using a predicate. The first stream will contain all element evaluated to true and the second one will contain all element evaluated to false. The faster stream may advance by up to buffer elements further than the slower one.
Split a stream by a predicate.
Split a stream by a predicate. The faster stream may advance by up to buffer elements further than the slower one.
Peels off enough material from the stream to construct an R
using the
provided ZSink and then returns both the R
and the remainder of the
ZStream in a managed resource.
Provides the stream with its required environment, which eliminates
its dependency on R
.
An effectual version of provide
, useful when the act of provision
requires an effect.
Uses the given Managed to provide the environment required to run this stream, leaving no outstanding environments.
Provides some of the environment required to run this effect,
leaving the remainder R0
.
Provides some of the environment required to run this effect,
leaving the remainder R0
.
Uses the given ZManaged to provide some of the environment required to run
this stream, leaving the remainder R0
.
Repeats the entire stream using the specified schedule.
Repeats the entire stream using the specified schedule. The stream will execute normally, and then repeat again according to the provided schedule.
Repeats the entire stream using the specified schedule.
Repeats the entire stream using the specified schedule. The stream will execute normally, and then repeat again according to the provided schedule. The schedule output will be emitted at the end of each repetition.
Repeats the entire stream using the specified schedule.
Repeats the entire stream using the specified schedule. The stream will execute normally, and then repeat again according to the provided schedule. The schedule output will be emitted at the end of each repetition and can be unified with the stream elements using the provided functions
Runs the sink on the stream to produce either the sink's result or an error.
Runs the stream and collects all of its elements in a list.
Runs the stream and collects all of its elements in a list.
Equivalent to run(Sink.collectAll[A])
.
Runs the stream purely for its effects.
Runs the stream purely for its effects. Any elements emitted by the stream are discarded.
Equivalent to run(Sink.drain)
.
Schedules the output of the stream using the provided schedule
and emits its output at
the end (if schedule
is finite).
Schedules the output of the stream using the provided schedule
and emits its output at
the end (if schedule
is finite).
Repeats each element of the stream using the provided schedule
, additionally emitting the schedule's output
each time a schedule is completed.
Repeats each element of the stream using the provided schedule
, additionally emitting the schedule's output
each time a schedule is completed.
Repeats are done in addition to the first execution, so that scheduleElements(Schedule.once)
means "emit element
and if not short circuited, repeat element once".
Repeats each element of the stream using the provided schedule
, additionally emitting the schedule's output
each time a schedule is completed.
Repeats each element of the stream using the provided schedule
, additionally emitting the schedule's output
each time a schedule is completed.
Repeats are done in addition to the first execution, so that scheduleElements(Schedule.once)
means "emit element
and if not short circuited, repeat element once".
Repeats each element of the stream using the provided schedule, additionally emitting the schedule's output each time a schedule is completed.
Repeats each element of the stream using the provided schedule, additionally emitting the schedule's output
each time a schedule is completed.
Repeats are done in addition to the first execution, so that scheduleElements(Schedule.once)
means "emit element
and if not short circuited, repeat element once".
Uses the provided functions to align the stream and schedule outputs on a common type.
Schedules the output of the stream using the provided schedule
and emits its output at
the end (if schedule
is finite).
Schedules the output of the stream using the provided schedule
and emits its output at
the end (if schedule
is finite).
Uses the provided function to align the stream and schedule outputs on the same type.
Takes the specified number of elements from this stream.
Takes all elements of the stream until the specified predicate evaluates
to true
.
Takes all elements of the stream for as long as the specified predicate
evaluates to true
.
Adds an effect to consumption of every element of the stream.
Throttles elements of type A according to the given bandwidth parameters using the token bucket algorithm.
Throttles elements of type A 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. Elements that do not meet the bandwidth constraints are dropped.
The weight of each element is determined by the costFn
function.
Throttles elements of type A according to the given bandwidth parameters using the token bucket algorithm.
Throttles elements of type A 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. Elements that do not meet the bandwidth constraints are dropped.
The weight of each element is determined by the costFn
effectful function.
Delays elements of type A according to the given bandwidth parameters using the token bucket algorithm.
Delays elements of type A 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 element is determined by the costFn
function.
Delays elements of type A according to the given bandwidth parameters using the token bucket algorithm.
Delays elements of type A 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 element is determined by the costFn
effectful function.
Interrupts the stream if it does not produce a value after d duration.
Converts the stream to a managed queue.
Converts the stream to a managed queue. After managed queue is used, the queue will never again produce values and should be discarded.
Applies a transducer to the stream, which converts one or more elements
of type A
into elements of type C
.
Applies a transducer to the stream, converting elements of type A
into elements of type C
, with a
managed resource of type D
available.
Filters any 'None'.
Filters any 'Take'.
Zips this stream together with the specified stream.
Runs this stream with the specified stream parallelly and keeps only values of this stream.
Runs this stream with the specified stream parallelly and keeps only values of specified stream.
Zips two streams together with a specified function.
Zips this stream together with the index of elements of the stream.
Zips the two streams so that when a value is emitted by either of the two streams, it is combined with the latest value from the other stream to produce a result.
(Since version 1.0.0) use scheduleElements
Analogical to spaced
but with distinction of stream elements and schedule output represented by Either
Analogical to spaced
but with distinction of stream elements and schedule output represented by Either
(Since version 1.0.0) use scheduleElementsEither
A
Stream[E, A]
represents an effectful stream that can produce values of typeA
, or potentially fail with a value of typeE
.Streams have a very similar API to Scala collections, making them immediately familiar to most developers. Unlike Scala collections, streams can be used on effectful streams of data, such as HTTP connections, files, and so forth.
Streams do not leak resources. This guarantee holds in the presence of early termination (not all of a stream is consumed), failure, or even interruption.
Thanks to only first-order types, appropriate variance annotations, and specialized effect type (ZIO), streams feature extremely good type inference and should almost never require specification of any type parameters.
process
is a low-level consumption method, usually used for creating combinators and constructors. For most usage, ZStream#fold, ZStream#foreach or ZStream#run should be preferred.The contract for the returned
Pull
is as follows: - It must not be evaluted concurrently from multiple fibers - it is (usually) not thread-safe; - If an evaluation of thePull
is interrupted, it is not safe to evaluate it again - it is (usually) not interruption-safe; - Once thePull
has failed with aNone
, it is not safe to evaluate it again.The managed
Pull
can be used to read from the stream until it is empty (or possibly forever, if the stream is infinite). The providedPull
is valid only inside the scope of the managed resource.