trait ZStream[-R, +E, +A] extends Serializable
A Stream[E, A] represents an effectful stream that can produce values of
type A, or potentially fail with a value of type E.
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.
- Self Type
- ZStream[R, E, A]
- Alphabetic
- By Inheritance
- ZStream
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Abstract Value Members
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##(): Int
- Definition Classes
- AnyRef → Any
- final def ++[R1 <: R, E1 >: E, A1 >: A](other: ZStream[R1, E1, A1]): ZStream[R1, E1, A1]
Concatenates with another stream in strict order
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def aggregate[R1 <: R, E1 >: E, A1 >: A, B](sink: ZSink[R1, E1, A1, A1, B]): ZStream[R1, E1, B]
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.
- final def aggregateWithin[R1 <: R, E1 >: E, A1 >: A, B, C](sink: ZSink[R1, E1, A1, A1, B], schedule: ZSchedule[R1, Option[B], C]): ZStream[R1 with Clock, E1, Either[C, 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.
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- final def buffer(capacity: Int): ZStream[R, E, A]
Allow a faster producer to progress independently of a slower consumer by buffering up to
capacityelements in a queue.Allow a faster producer to progress independently of a slower consumer by buffering up to
capacityelements in a queue.- Note
when possible, prefer capacities that are powers of 2 for better performance.
- def clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def collect[B](pf: PartialFunction[A, B]): ZStream[R, E, B]
Performs a filter and map in a single step.
- def collectWhile[B](pred: PartialFunction[A, B]): ZStream[R, E, B]
Transforms all elements of the stream for as long as the specified partial function is defined.
- final def concat[R1 <: R, E1 >: E, A1 >: A](other: ZStream[R1, E1, A1]): ZStream[R1, E1, A1]
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
otherstream. - final def drain: ZStream[R, E, Nothing]
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)
- final def drop(n: Int): ZStream[R, E, A]
Drops the specified number of elements from this stream.
- def dropWhile(pred: (A) => Boolean): ZStream[R, E, A]
Drops all elements of the stream for as long as the specified predicate evaluates to
true. - def ensuring[R1 <: R](fin: ZIO[R1, Nothing, _]): ZStream[R1, E, A]
Executes the provided finalizer after this stream's finalizers run.
- def ensuringFirst[R1 <: R](fin: ZIO[R1, Nothing, _]): ZStream[R1, E, A]
Executes the provided finalizer before this stream's finalizers run.
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def filter(pred: (A) => Boolean): ZStream[R, E, A]
Filters this stream by the specified predicate, retaining all elements for which the predicate evaluates to true.
- final def filterM[R1 <: R, E1 >: E](pred: (A) => ZIO[R1, E1, Boolean]): ZStream[R1, E1, A]
Filters this stream by the specified effectful predicate, retaining all elements for which the predicate evaluates to true.
- final def filterNot(pred: (A) => Boolean): ZStream[R, E, A]
Filters this stream by the specified predicate, removing all elements for which the predicate evaluates to true.
- def finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def flatMap[R1 <: R, E1 >: E, B](f0: (A) => ZStream[R1, E1, B]): ZStream[R1, E1, B]
Returns a stream made of the concatenation in strict order of all the streams produced by passing each element of this stream to
f0 - final def flatMapPar[R1 <: R, E1 >: E, B](n: Int, outputBuffer: Int = 16)(f: (A) => ZStream[R1, E1, B]): ZStream[R1, E1, B]
Maps each element of this stream to another stream and returns the non-deterministic merge of those streams, executing up to
ninner streams concurrently.Maps each element of this stream to another stream and returns the non-deterministic merge of those streams, executing up to
ninner streams concurrently. Up tooutputBufferelements of the produced streams may be buffered in memory by this operator. - final def flatMapParSwitch[R1 <: R, E1 >: E, B](n: Int, bufferSize: Int = 16)(f: (A) => ZStream[R1, E1, B]): ZStream[R1, E1, B]
Maps each element of this stream to another stream and returns the non-deterministic merge of those streams, executing up to
ninner streams concurrently.Maps each element of this stream to another stream and returns the non-deterministic merge of those streams, executing up to
ninner streams concurrently. When a new stream is created from an element of the source stream, the oldest executing stream is cancelled. Up tobufferSizeelements of the produced streams may be buffered in memory by this operator. - def foldLeft[A1 >: A, S](s: S)(f: (S, A1) => S): ZManaged[R, E, S]
Reduces the elements in the stream to a value of type
S - final def foreach[R1 <: R, E1 >: E](f: (A) => ZIO[R1, E1, Unit]): ZIO[R1, E1, Unit]
Consumes all elements of the stream, passing them to the specified callback.
- final def foreachManaged[R1 <: R, E1 >: E](f: (A) => ZIO[R1, E1, Unit]): ZManaged[R1, E1, Unit]
Like ZStream#foreach, but returns a
ZManagedso the finalization order can be controlled. - final def foreachWhile[R1 <: R, E1 >: E](f: (A) => ZIO[R1, E1, Boolean]): ZIO[R1, E1, Unit]
Consumes elements of the stream, passing them to the specified callback, and terminating consumption when the callback returns
false. - final def foreachWhileManaged[R1 <: R, E1 >: E](f: (A) => ZIO[R1, E1, Boolean]): ZManaged[R1, E1, Unit]
Like ZStream#foreachWhile, but returns a
ZManagedso the finalization order can be controlled. - def forever: ZStream[R, E, A]
Repeats this stream forever.
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def into[R1 <: R, E1 >: E, A1 >: A](queue: ZQueue[R1, E1, _, _, Take[E1, A1], _]): ZIO[R1, E1, Unit]
Enqueues elements of this stream into a queue.
Enqueues elements of this stream into a queue. Stream failure and ending will also be signalled.
- def intoManaged[R1 <: R, E1 >: E, A1 >: A](queue: ZQueue[R1, E1, _, _, Take[E1, A1], _]): ZManaged[R1, E1, Unit]
Like ZStream#into, but provides the result as a ZManaged to allow for scope composition.
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def map[B](f0: (A) => B): ZStream[R, E, B]
Returns a stream made of the elements of this stream transformed with
f0 - def mapAccum[S1, B](s1: S1)(f1: (S1, A) => (S1, B)): ZStream[R, E, B]
Statefully maps over the elements of this stream to produce new elements.
- final def mapAccumM[R1 <: R, E1 >: E, S1, B](s1: S1)(f1: (S1, A) => ZIO[R1, E1, (S1, B)]): ZStream[R1, E1, B]
Statefully and effectfully maps over the elements of this stream to produce new elements.
- def mapConcat[B](f: (A) => Chunk[B]): ZStream[R, E, B]
Maps each element to a chunk, and flattens the chunks into the output of this stream.
- def mapConcatM[R1 <: R, E1 >: E, B](f: (A) => ZIO[R1, E1, Chunk[B]]): ZStream[R1, E1, B]
Effectfully maps each element to a chunk, and flattens the chunks into the output of this stream.
- final def mapM[R1 <: R, E1 >: E, B](f: (A) => ZIO[R1, E1, B]): ZStream[R1, E1, B]
Maps over elements of the stream with the specified effectful function.
- final def mapMPar[R1 <: R, E1 >: E, B](n: Int)(f: (A) => ZIO[R1, E1, B]): ZStream[R1, E1, B]
Maps over elements of the stream with the specified effectful function, executing up to
ninvocations offconcurrently.Maps over elements of the stream with the specified effectful function, executing up to
ninvocations offconcurrently. Transformed elements will be emitted in the original order. - final def mapMParUnordered[R1 <: R, E1 >: E, B](n: Int)(f: (A) => ZIO[R1, E1, B]): ZStream[R1, E1, B]
Maps over elements of the stream with the specified effectful function, executing up to
ninvocations offconcurrently.Maps over elements of the stream with the specified effectful function, executing up to
ninvocations offconcurrently. The element order is not enforced by this combinator, and elements may be reordered. - final def merge[R1 <: R, E1 >: E, A1 >: A](that: ZStream[R1, E1, A1], capacity: Int = 2): ZStream[R1, E1, A1]
Merges this stream and the specified stream together.
- final def mergeEither[R1 <: R, E1 >: E, B](that: ZStream[R1, E1, B], capacity: Int = 2): ZStream[R1, E1, Either[A, B]]
Merges this stream and the specified stream together to produce a stream of eithers.
- final def mergeWith[R1 <: R, E1 >: E, B, C](that: ZStream[R1, E1, B], capacity: Int = 2)(l: (A) => C, r: (B) => C): ZStream[R1, E1, C]
Merges this stream and the specified stream together to a common element type with the specified mapping functions.
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def peel[R1 <: R, E1 >: E, A1 >: A, B](sink: ZSink[R1, E1, A1, A1, B]): ZManaged[R1, E1, (B, ZStream[R1, E1, A1])]
Peels off enough material from the stream to construct an
Rusing the providedSink, and then returns both theRand the remainder of theStreamin a managed resource.Peels off enough material from the stream to construct an
Rusing the providedSink, and then returns both theRand the remainder of theStreamin a managed resource. Like allManagedresources, the provided remainder is valid only within the scope ofManaged. - def repeat[R1 <: R](schedule: ZSchedule[R1, Unit, _]): ZStream[R1 with Clock, E, A]
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.
- def run[R1 <: R, E1 >: E, A0, A1 >: A, B](sink: ZSink[R1, E1, A0, A1, B]): ZIO[R1, E1, B]
Runs the sink on the stream to produce either the sink's result or an error.
- def runCollect: ZIO[R, E, List[A]]
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]). - def runDrain: ZIO[R, E, Unit]
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). - def spaced[R1 <: R, A1 >: A](schedule: ZSchedule[R1, A, A1]): ZStream[R1 with Clock, E, A1]
Repeats each element of the stream using the provided schedule, additionally emitting schedule's output, each time a schedule is completed.
Repeats each element of the stream using the provided schedule, additionally emitting schedule's output, each time a schedule is completed. Repeats are done in addition to the first execution, so that
spaced(Schedule.once)means "emit element and if not short circuited, repeat element once". - def spacedEither[R1 <: R, B](schedule: ZSchedule[R1, A, B]): ZStream[R1 with Clock, E, Either[B, A]]
Analogical to
spacedbut with distinction of stream elements and schedule output represented by Either - final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- final def take(n: Int): ZStream[R, E, A]
Takes the specified number of elements from this stream.
- def takeWhile(pred: (A) => Boolean): ZStream[R, E, A]
Takes all elements of the stream for as long as the specified predicate evaluates to
true. - final def tap[R1 <: R, E1 >: E](f: (A) => ZIO[R1, E1, _]): ZStream[R1, E1, A]
Adds an effect to consumption of every element of the stream.
- final def throttleEnforce(units: Long, duration: Duration, burst: Long = 0)(costFn: (A) => Long): ZStream[R with Clock, E, A]
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 + burstthreshold. Elements that do not meet the bandwidth constraints are dropped. The weight of each element is determined by thecostFnfunction. - final def throttleEnforceM[R1 <: R, E1 >: E](units: Long, duration: Duration, burst: Long = 0)(costFn: (A) => ZIO[R1, E1, Long]): ZStream[R1 with Clock, E1, A]
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 + burstthreshold. Elements that do not meet the bandwidth constraints are dropped. The weight of each element is determined by thecostFneffectful function. - final def throttleShape(units: Long, duration: Duration, burst: Long = 0)(costFn: (A) => Long): ZStream[R with Clock, E, A]
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 + burstthreshold. The weight of each element is determined by thecostFnfunction. - final def throttleShapeM[R1 <: R, E1 >: E](units: Long, duration: Duration, burst: Long = 0)(costFn: (A) => ZIO[R1, E1, Long]): ZStream[R1 with Clock, E1, A]
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 + burstthreshold. The weight of each element is determined by thecostFneffectful function. - final def toQueue[E1 >: E, A1 >: A](capacity: Int = 2): ZManaged[R, E1, Queue[Take[E1, A1]]]
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.
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def transduce[R1 <: R, E1 >: E, A1 >: A, C](sink: ZSink[R1, E1, A1, A1, C]): ZStream[R1, E1, C]
Applies a transducer to the stream, which converts one or more elements of type
Ainto elements of typeC. - final def transduceManaged[R1 <: R, E1 >: E, A1 >: A, C](managedSink: ZManaged[R1, E1, ZSink[R1, E1, A1, A1, C]]): ZStream[R1, E1, C]
Applies a transducer to the stream, converting elements of type
Ainto elements of typeC, with a managed resource of typeDavailable. - final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def zip[R1 <: R, E1 >: E, B](that: ZStream[R1, E1, B], lc: Int = 2, rc: Int = 2): ZStream[R1, E1, (A, B)]
Zips this stream together with the specified stream.
- final def zipWith[R1 <: R, E1 >: E, B, C](that: ZStream[R1, E1, B], lc: Int = 2, rc: Int = 2)(f0: (Option[A], Option[B]) => Option[C]): ZStream[R1, E1, C]
Zips two streams together with a specified function.
- def zipWithIndex: ZStream[R, E, (A, Int)]
Zips this stream together with the index of elements of the stream.