Stream

fs2.Stream
See theStream companion class
object Stream

Attributes

Companion
class
Source
Stream.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Stream.type

Members list

Type members

Classlikes

final class CompileOps[F[_], G[_], O]

Projection of a Stream providing various ways to compile a Stream[F,O] to a G[...].

Projection of a Stream providing various ways to compile a Stream[F,O] to a G[...].

Attributes

Source
Stream.scala
Supertypes
class Object
trait Matchable
class Any
final implicit class FallibleOps[O](self: Stream[Fallible, O]) extends AnyVal

Provides syntax for fallible streams.

Provides syntax for fallible streams.

Attributes

Source
Stream.scala
Supertypes
class AnyVal
trait Matchable
class Any
final implicit class IdOps[O](self: Stream[Id, O]) extends AnyVal

Provides syntax for pure pipes based on cats.Id.

Provides syntax for pure pipes based on cats.Id.

Attributes

Source
Stream.scala
Supertypes
class AnyVal
trait Matchable
class Any
final implicit class InvariantOps[F[_], O](self: Stream[F, O]) extends AnyVal

A view of Stream that removes the variance from the type parameters.

A view of Stream that removes the variance from the type parameters. This allows defining syntax in which the type parameters appear in contravariant (i.e. input) position, which would fail to compile if defined as instance methods.

Attributes

Source
Stream.scala
Supertypes
class AnyVal
trait Matchable
class Any
final implicit class NestedStreamOps[F[_], O](outer: Stream[F, Stream[F, O]]) extends AnyVal

Provides syntax for streams of streams.

Provides syntax for streams of streams.

Attributes

Source
Stream.scala
Supertypes
class AnyVal
trait Matchable
class Any
final implicit class NothingStreamOps[F[_]](self: Stream[F, Nothing]) extends AnyVal

Attributes

Source
Stream.scala
Supertypes
class AnyVal
trait Matchable
class Any
final implicit class OptionStreamOps[F[_], O](self: Stream[F, Option[O]]) extends AnyVal

Attributes

Source
Stream.scala
Supertypes
class AnyVal
trait Matchable
class Any
final class PartiallyAppliedFromBlockingIterator[F[_]] extends AnyVal

Attributes

Source
Stream.scala
Supertypes
class AnyVal
trait Matchable
class Any
final class PartiallyAppliedFromIterator[F[_]] extends AnyVal

Attributes

Companion
object
Source
Stream.scala
Supertypes
class AnyVal
trait Matchable
class Any

Attributes

Companion
class
Source
Stream.scala
Supertypes
class Object
trait Matchable
class Any
Self type
final implicit class PipeOps[F[_], I, O](self: (F, I) => O) extends AnyVal

Provides operations on effectful pipes for syntactic convenience.

Provides operations on effectful pipes for syntactic convenience.

Attributes

Source
Stream.scala
Supertypes
class AnyVal
trait Matchable
class Any
final implicit class PureOps[O](self: Stream[Pure, O]) extends AnyVal

Provides syntax for pure streams.

Provides syntax for pure streams.

Attributes

Source
Stream.scala
Supertypes
class AnyVal
trait Matchable
class Any
final implicit class PurePipe2Ops[I, I2, O](self: (Pure, I, I2) => O) extends AnyVal

Provides operations on pure pipes for syntactic convenience.

Provides operations on pure pipes for syntactic convenience.

Attributes

Source
Stream.scala
Supertypes
class AnyVal
trait Matchable
class Any
final implicit class PurePipeOps[I, O](self: (Pure, I) => O) extends AnyVal

Provides operations on pure pipes for syntactic convenience.

Provides operations on pure pipes for syntactic convenience.

Attributes

Source
Stream.scala
Supertypes
class AnyVal
trait Matchable
class Any
final class StepLeg[+F[_], +O](val head: Chunk[O], val scopeId: Token, val next: Pull[F, O, Unit])

When merging multiple streams, this represents step of one leg.

When merging multiple streams, this represents step of one leg.

It is common to uncons, however unlike uncons, it keeps track of stream scope independently of the main scope of the stream.

This assures, that after each next stepLeg each Stream leg keeps its scope when interpreting.

Usual scenarios is to first invoke stream.pull.stepLeg and then consume whatever is available in leg.head. If the next step is required leg.stepLeg will yield next Leg.

Once the stream will stop to be interleaved (merged), then stream allows to return to normal stream invocation.

Attributes

Source
Stream.scala
Supertypes
class Object
trait Matchable
class Any
Self type
StepLeg[F, O]
final class ToPull[F[_], O] extends AnyVal

Projection of a Stream providing various ways to get a Pull from the Stream.

Projection of a Stream providing various ways to get a Pull from the Stream.

Attributes

Source
Stream.scala
Supertypes
class AnyVal
trait Matchable
class Any

Value members

Concrete methods

def apply[F[x], O](os: O*): Stream[F, O]

Creates a pure stream that emits the supplied values.

Creates a pure stream that emits the supplied values. To convert to an effectful stream, use covary.

Attributes

Source
Stream.scala
def attemptEval[F[_], O](fo: F[O]): Stream[F, Either[Throwable, O]]

Creates a single element stream that gets its value by evaluating the supplied effect.

Creates a single element stream that gets its value by evaluating the supplied effect. If the effect fails, a Left is emitted. Otherwise, a Right is emitted.

Use eval instead if a failure while evaluating the effect should fail the stream.

Attributes

Example

scala> import cats.effect.SyncIO
scala> Stream.attemptEval(SyncIO(10)).compile.toVector.unsafeRunSync()
res0: Vector[Either[Throwable,Int]] = Vector(Right(10))
scala> Stream.attemptEval(SyncIO(throw new RuntimeException)).compile.toVector.unsafeRunSync()
res1: Vector[Either[Throwable,Nothing]] = Vector(Left(java.lang.RuntimeException))
Source
Stream.scala

Light weight alternative to awakeEvery that sleeps for duration d before each pulled element.

Light weight alternative to awakeEvery that sleeps for duration d before each pulled element.

Attributes

Source
Stream.scala

Discrete stream that every d emits elapsed duration since the start time of stream consumption.

Discrete stream that every d emits elapsed duration since the start time of stream consumption.

Missed periods are dampened to a single tick.

For example: awakeEvery[IO](5 seconds) will return (approximately) 5s, 10s, 15s, and will lie dormant between emitted values.

Value parameters

period

duration between emits of the resulting stream

Attributes

Source
Stream.scala

Discrete stream that every d emits elapsed duration since the start time of stream consumption.

Discrete stream that every d emits elapsed duration since the start time of stream consumption.

For example: awakeEvery[IO](5 seconds) will return (approximately) 5s, 10s, 15s, and will lie dormant between emitted values.

Value parameters

dampen

whether missed periods result in 1 emitted tick or 1 per missed period, see fixedRate for more info

period

duration between emits of the resulting stream

Attributes

Source
Stream.scala
def bracket[F[_], R](acquire: F[R])(release: R => F[Unit]): Stream[F, R]

Creates a stream that emits a resource allocated by an effect, ensuring the resource is eventually released regardless of how the stream is used.

Creates a stream that emits a resource allocated by an effect, ensuring the resource is eventually released regardless of how the stream is used.

A typical use case for bracket is working with files or network sockets. The resource effect opens a file and returns a reference to it. One can then flatMap on the returned Stream to access the file, e.g to read bytes and transform them in to some stream of elements (e.g., bytes, strings, lines, etc.). The release action then closes the file once the result Stream terminates, even in case of interruption or errors.

Value parameters

acquire

resource to acquire at start of stream

release

function which returns an effect that releases the resource

Attributes

Source
Stream.scala
def bracketCase[F[_], R](acquire: F[R])(release: (R, ExitCase) => F[Unit]): Stream[F, R]

Like bracket but the release action is passed an ExitCase[Throwable].

Like bracket but the release action is passed an ExitCase[Throwable].

ExitCase.Canceled is passed to the release action in the event of either stream interruption or overall compiled effect cancelation.

Attributes

Source
Stream.scala
def bracketCaseWeak[F[_], R](acquire: F[R])(release: (R, ExitCase) => F[Unit]): Stream[F, R]

Like bracketCase but no scope is introduced, causing resource finalization to occur at the end of the current scope at the time of acquisition.

Like bracketCase but no scope is introduced, causing resource finalization to occur at the end of the current scope at the time of acquisition.

Attributes

Source
Stream.scala
def bracketFull[F[_], R](acquire: Poll[F] => F[R])(release: (R, ExitCase) => F[Unit])(implicit F: MonadCancel[F, _]): Stream[F, R]

Like bracketCase but the acquire action may be canceled.

Like bracketCase but the acquire action may be canceled.

Attributes

Source
Stream.scala
def bracketFullWeak[F[_], R](acquire: Poll[F] => F[R])(release: (R, ExitCase) => F[Unit])(implicit F: MonadCancel[F, _]): Stream[F, R]

Like bracketFull but no scope is introduced, causing resource finalization to occur at the end of the current scope at the time of acquisition.

Like bracketFull but no scope is introduced, causing resource finalization to occur at the end of the current scope at the time of acquisition.

Attributes

Source
Stream.scala
def bracketWeak[F[_], R](acquire: F[R])(release: R => F[Unit]): Stream[F, R]

Like bracket but no scope is introduced, causing resource finalization to occur at the end of the current scope at the time of acquisition.

Like bracket but no scope is introduced, causing resource finalization to occur at the end of the current scope at the time of acquisition.

Attributes

Source
Stream.scala
def chunk[F[x], O](os: Chunk[O]): Stream[F, O]

Creates a pure stream that emits the elements of the supplied chunk.

Creates a pure stream that emits the elements of the supplied chunk.

Attributes

Example

scala> Stream.chunk(Chunk(1,2,3)).toList
res0: List[Int] = List(1, 2, 3)
Source
Stream.scala
def constant[F[x], O](o: O, chunkSize: Int): Stream[F, O]

Creates an infinite pure stream that always returns the supplied value.

Creates an infinite pure stream that always returns the supplied value.

Elements are emitted in finite chunks with chunkSize number of elements.

Attributes

Example

scala> Stream.constant(0).take(5).toList
res0: List[Int] = List(0, 0, 0, 0, 0)
Source
Stream.scala
def duration[F[_]](implicit F: Clock[F]): Stream[F, FiniteDuration]

A continuous stream of the elapsed time, computed using System.nanoTime.

A continuous stream of the elapsed time, computed using System.nanoTime. Note that the actual granularity of these elapsed times depends on the OS, for instance the OS may only update the current time every ten milliseconds or so.

Attributes

Source
Stream.scala
def emit[F[x], O](o: O): Stream[F, O]

Creates a singleton pure stream that emits the supplied value.

Creates a singleton pure stream that emits the supplied value.

Attributes

Example

scala> Stream.emit(0).toList
res0: List[Int] = List(0)
Source
Stream.scala
def emits[F[x], O](os: Seq[O]): Stream[F, O]

Creates a pure stream that emits the supplied values.

Creates a pure stream that emits the supplied values.

Attributes

Example

scala> Stream.emits(List(1, 2, 3)).toList
res0: List[Int] = List(1, 2, 3)
Source
Stream.scala
def eval[F[_], O](fo: F[O]): Stream[F, O]

Creates a single element stream that gets its value by evaluating the supplied effect.

Creates a single element stream that gets its value by evaluating the supplied effect. If the effect fails, the returned stream fails.

Use attemptEval instead if a failure while evaluating the effect should be emitted as a value.

Attributes

Example

scala> import cats.effect.SyncIO
scala> Stream.eval(SyncIO(10)).compile.toVector.unsafeRunSync()
res0: Vector[Int] = Vector(10)
scala> Stream.eval(SyncIO(throw new RuntimeException)).covaryOutput[Int].compile.toVector.attempt.unsafeRunSync()
res1: Either[Throwable,Vector[Int]] = Left(java.lang.RuntimeException)
Source
Stream.scala
def evalSeq[F[_], S <: (Seq), O](fo: F[S[O]]): Stream[F, O]

Like evals, but lifts any Seq in the effect.

Like evals, but lifts any Seq in the effect.

Attributes

Source
Stream.scala
def evalUnChunk[F[_], O](fo: F[Chunk[O]]): Stream[F, O]

Like eval but resulting chunk is flatten efficiently.

Like eval but resulting chunk is flatten efficiently.

Attributes

Source
Stream.scala
def evals[F[_], S[_] : Foldable, O](fo: F[S[O]]): Stream[F, O]

Like eval, but lifts a foldable structure.

Like eval, but lifts a foldable structure.

Attributes

Source
Stream.scala
def every[F[_]](d: FiniteDuration)(implicit clock: Clock[F], F: Functor[F]): Stream[F, Boolean]

A continuous stream which is true after d, 2d, 3d... elapsed duration, and false otherwise.

A continuous stream which is true after d, 2d, 3d... elapsed duration, and false otherwise. If you'd like a 'discrete' stream that will actually block until d has elapsed, use awakeEvery instead.

Attributes

Source
Stream.scala
def exec[F[_]](action: F[Unit]): Stream[F, Nothing]

As a result, the returned stream emits no elements and hence has output type Nothing.

As a result, the returned stream emits no elements and hence has output type Nothing.

Attributes

Example

scala> import cats.effect.SyncIO
scala> Stream.exec(SyncIO(println("Ran"))).covaryOutput[Int].compile.toVector.unsafeRunSync()
res0: Vector[Int] = Vector()
Source
Stream.scala
def fixedDelay[F[_]](period: FiniteDuration)(implicit t: Temporal[F]): Stream[F, Unit]

Light weight alternative to fixedRate that sleeps for duration d before each pulled element.

Light weight alternative to fixedRate that sleeps for duration d before each pulled element.

Behavior differs from fixedRate because the sleep between elements occurs after the next element is pulled whereas fixedRate accounts for the time it takes to process the emitted unit. This difference can roughly be thought of as the difference between scheduleWithFixedDelay and scheduleAtFixedRate in java.util.concurrent.Scheduler.

Alias for sleep(period).repeat.

Attributes

Source
Stream.scala
def fixedRate[F[_]](period: FiniteDuration)(implicit t: Temporal[F]): Stream[F, Unit]

Discrete stream that emits a unit every d, with missed period ticks dampened.

Discrete stream that emits a unit every d, with missed period ticks dampened.

See fixedDelay for an alternative that sleeps d between elements.

Value parameters

period

duration between emits of the resulting stream

Attributes

Source
Stream.scala

Discrete stream that emits a unit every d.

Discrete stream that emits a unit every d.

See fixedDelay for an alternative that sleeps d between elements.

This operation differs in that the time between ticks should roughly be equal to the specified period, regardless of how much time it takes to process that tick downstream. For example, with a 1 second period and a task that takes 100ms, the task would run at timestamps, 1s, 2s, 3s, etc. when using fixedRate >> task whereas it would run at timestamps 1s, 2.1s, 3.2s, etc. when using fixedDelay >> task.

In the case where task processing takes longer than a single period, 1 or more ticks are immediately emitted to "catch-up". The dampen parameter controls whether a single tick is emitted or whether one per missed period is emitted.

Value parameters

dampen

true if a single unit should be emitted when multiple periods have passed since last execution, false if a unit for each period should be emitted

period

period between emits of the resulting stream

Attributes

Source
Stream.scala

Discrete stream that emits a unit every d, with missed period ticks dampened.

Discrete stream that emits a unit every d, with missed period ticks dampened.

Unlike fixedRate, it doesn't wait for d before emitting the first unit.

Value parameters

period

duration between emits of the resulting stream

Attributes

Source
Stream.scala

Discrete stream that emits a unit every d.

Discrete stream that emits a unit every d.

Unlike fixedRate, it doesn't wait for d before emitting the first unit.

Value parameters

dampen

true if a single unit should be emitted when multiple periods have passed since last execution, false if a unit for each period should be emitted

period

duration between emits of the resulting stream

Attributes

Source
Stream.scala
def foldable[F[x], G[_] : Foldable, O](os: G[O]): Stream[F, O]

Like emits, but works for any G that has a Foldable instance.

Like emits, but works for any G that has a Foldable instance.

Attributes

Source
Stream.scala
def force[F[_], A](f: F[Stream[F, A]]): Stream[F, A]

Lifts an effect that generates a stream in to a stream.

Lifts an effect that generates a stream in to a stream. Alias for eval(f).flatMap(_).

Attributes

Example

scala> import cats.effect.SyncIO
scala> Stream.force(SyncIO(Stream(1,2,3).covary[SyncIO])).compile.toVector.unsafeRunSync()
res0: Vector[Int] = Vector(1, 2, 3)
Source
Stream.scala
def fromAutoCloseable[F[_] : Sync, O <: AutoCloseable](fo: F[O]): Stream[F, O]

Converts the supplied java.lang.AutoCloseable into a singleton stream.

Converts the supplied java.lang.AutoCloseable into a singleton stream.

Attributes

Source
Stream.scala
def fromAutoCloseableWeak[F[_] : Sync, O <: AutoCloseable](fo: F[O]): Stream[F, O]

Like fromAutoCloseable but does not introduce a scope, allowing finalization to occur after subsequent appends or other scope-preserving transformations.

Like fromAutoCloseable but does not introduce a scope, allowing finalization to occur after subsequent appends or other scope-preserving transformations.

Scopes can be manually introduced via Stream#scope if desired.

Attributes

Source
Stream.scala

Lifts an iterator into a Stream, shifting any interaction with the iterator to the blocking pool.

Lifts an iterator into a Stream, shifting any interaction with the iterator to the blocking pool.

Attributes

Source
Stream.scala
def fromEither[F[_]]: PartiallyAppliedFromEither[F]

Lifts an Either[Throwable, A] to an effectful Stream.

Lifts an Either[Throwable, A] to an effectful Stream.

Attributes

Example

scala> import cats.effect.SyncIO, scala.util.Try
scala> Stream.fromEither[SyncIO](Right(42)).compile.toList.unsafeRunSync()
res0: List[Int] = List(42)
scala> Try(Stream.fromEither[SyncIO](Left(new RuntimeException)).compile.toList.unsafeRunSync())
res1: Try[List[Nothing]] = Failure(java.lang.RuntimeException)
Source
Stream.scala

Lifts an iterator into a Stream.

Lifts an iterator into a Stream.

Attributes

Source
Stream.scala
def fromOption[F[_]]: PartiallyAppliedFromOption[F]

Lifts an Option[A] to an effectful Stream.

Lifts an Option[A] to an effectful Stream.

Attributes

Example

scala> import cats.effect.SyncIO
scala> Stream.fromOption[SyncIO](Some(42)).compile.toList.unsafeRunSync()
res0: List[Int] = List(42)
scala> Stream.fromOption[SyncIO](None).compile.toList.unsafeRunSync()
res1: List[Nothing] = List()
Source
Stream.scala

Returns a stream of elements from the supplied queue.

Returns a stream of elements from the supplied queue.

The stream terminates upon dequeuing a None.

All elements that are available, up to the specified limit, are dequeued and emitted as a single chunk.

Attributes

Source
Stream.scala

Returns a stream of elements from the supplied queue.

Returns a stream of elements from the supplied queue.

The stream terminates upon dequeuing a None.

All elements that are available, up to the specified limit, are dequeued and emitted as a single chunk.

Attributes

Source
Stream.scala

Returns a stream of elements from the supplied queue.

Returns a stream of elements from the supplied queue.

The stream terminates upon dequeuing a None.

All elements that are available, up to the specified limit, are dequeued and emitted as a single chunk.

Attributes

Source
Stream.scala

Returns a stream of elements from the supplied queue.

Returns a stream of elements from the supplied queue.

The stream terminates upon dequeuing a None.

All elements that are available, up to the specified limit, are dequeued and emitted as a single chunk.

Attributes

Source
Stream.scala
def fromQueueUnterminated[F[_], A](queue: QueueSource[F, A], limit: Int)(implicit F: Functor[F]): Stream[F, A]

Returns a stream of elements from the supplied queue.

Returns a stream of elements from the supplied queue.

All elements that are available, up to the specified limit, are dequeued and emitted as a single chunk.

Attributes

Source
Stream.scala

Returns a stream of elements from the supplied queue.

Returns a stream of elements from the supplied queue.

All elements that are available, up to the specified limit, are dequeued and emitted as a single chunk.

Attributes

Source
Stream.scala

Returns a stream of elements from the supplied queue.

Returns a stream of elements from the supplied queue.

All elements that are available, up to the specified limit, are dequeued and emitted as a single chunk.

Attributes

Source
Stream.scala

Returns a stream of elements from the supplied queue.

Returns a stream of elements from the supplied queue.

All elements that are available, up to the specified limit, are dequeued and emitted as a single chunk.

Attributes

Source
Stream.scala
def iterable[F[x], A](os: Iterable[A]): Stream[F, A]

Like emits, but works for any class that extends Iterable

Like emits, but works for any class that extends Iterable

Attributes

Source
Stream.scala
def iterate[F[x], A](start: A)(f: A => A): Stream[F, A]

An infinite Stream that repeatedly applies a given function to a start value.

An infinite Stream that repeatedly applies a given function to a start value. start is the first value emitted, followed by f(start), then f(f(start)), and so on.

Attributes

Example

scala> Stream.iterate(0)(_ + 1).take(10).toList
res0: List[Int] = List(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
Source
Stream.scala
def iterateEval[F[_], A](start: A)(f: A => F[A]): Stream[F, A]

Like iterate, but takes an effectful function for producing the next state.

Like iterate, but takes an effectful function for producing the next state. start is the first value emitted.

Attributes

Example

scala> import cats.effect.SyncIO
scala> Stream.iterateEval(0)(i => SyncIO(i + 1)).take(10).compile.toVector.unsafeRunSync()
res0: Vector[Int] = Vector(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
Source
Stream.scala
def never[F[_]](implicit F: Spawn[F]): Stream[F, Nothing]

A stream that never emits and never terminates.

A stream that never emits and never terminates.

Attributes

Source
Stream.scala
def raiseError[F[_] : RaiseThrowable](e: Throwable): Stream[F, Nothing]

Creates a stream that, when run, fails with the supplied exception.

Creates a stream that, when run, fails with the supplied exception.

The F type must be explicitly provided (e.g., via raiseError[IO] or raiseError[Fallible]).

Attributes

Example

scala> import cats.effect.SyncIO
scala> Stream.raiseError[Fallible](new RuntimeException).toList
res0: Either[Throwable,List[Nothing]] = Left(java.lang.RuntimeException)
scala> Stream.raiseError[SyncIO](new RuntimeException).covaryOutput[Int].compile.drain.attempt.unsafeRunSync()
res0: Either[Throwable,Unit] = Left(java.lang.RuntimeException)
Source
Stream.scala
def range[F[x], O : Numeric](start: O, stopExclusive: O): Stream[F, O]

Lazily produces the sequence [start, start + 1, start + 2, ..., stopExclusive).

Lazily produces the sequence [start, start + 1, start + 2, ..., stopExclusive). If you want to produce the sequence in one chunk, instead of lazily, use emits(start until stopExclusive).

Attributes

Example

scala> Stream.range(10, 20).toList
res0: List[Int] = List(10, 11, 12, 13, 14, 15, 16, 17, 18, 19)
Source
Stream.scala
def range[F[x], O : Numeric](start: O, stopExclusive: O, step: O): Stream[F, O]

Lazily produce the sequence [start, start + step, start + 2 * step, ..., stopExclusive).

Lazily produce the sequence [start, start + step, start + 2 * step, ..., stopExclusive). If you want to produce the sequence in one chunk, instead of lazily, use emits(start until stopExclusive by step).

Attributes

Example

scala> Stream.range(10, 20, 2).toList
res0: List[Int] = List(10, 12, 14, 16, 18)
Source
Stream.scala

Lazily produce a sequence of nonoverlapping ranges, where each range contains size integers, assuming the upper bound is exclusive.

Lazily produce a sequence of nonoverlapping ranges, where each range contains size integers, assuming the upper bound is exclusive. Example: ranges(0, 1000, 10) results in the pairs (0, 10), (10, 20), (20, 30) ... (990, 1000)

Note: The last emitted range may be truncated at stopExclusive. For instance, ranges(0,5,4) results in (0,4), (4,5).

Attributes

Throws
Example

scala> Stream.ranges(0, 20, 5).toList
res0: List[(Int,Int)] = List((0,5), (5,10), (10,15), (15,20))
Source
Stream.scala
def repeatEval[F[_], O](fo: F[O]): Stream[F, O]

Alias for eval(fo).repeat.

Alias for eval(fo).repeat.

Attributes

Source
Stream.scala
def resource[F[_], O](r: Resource[F, O])(implicit F: MonadCancel[F, _]): Stream[F, O]

Converts the supplied resource into a singleton stream.

Converts the supplied resource into a singleton stream.

Attributes

Source
Stream.scala
def resourceK[F[_]](implicit F: MonadCancel[F, _]): FunctionK[[_] =>> Resource[F, _$143], [_] =>> Stream[F, _$144]]

Same as resource, but expressed as a FunctionK.

Same as resource, but expressed as a FunctionK.

Attributes

Source
Stream.scala
def resourceWeak[F[_], O](r: Resource[F, O])(implicit F: MonadCancel[F, _]): Stream[F, O]

Like resource but does not introduce a scope, allowing finalization to occur after subsequent appends or other scope-preserving transformations.

Like resource but does not introduce a scope, allowing finalization to occur after subsequent appends or other scope-preserving transformations.

Scopes can be manually introduced via Stream#scope if desired.

Attributes

Source
Stream.scala
def resourceWeakK[F[_]](implicit F: MonadCancel[F, _]): FunctionK[[_] =>> Resource[F, _$150], [_] =>> Stream[F, _$151]]

Same as resourceWeak, but expressed as a FunctionK.

Same as resourceWeak, but expressed as a FunctionK.

Attributes

Source
Stream.scala

Retries fo on failure, returning a singleton stream with the result of fo as soon as it succeeds.

Retries fo on failure, returning a singleton stream with the result of fo as soon as it succeeds.

Value parameters

delay

Duration of delay before the first retry

maxAttempts

Number of attempts before failing with the latest error, if fo never succeeds

nextDelay

Applied to the previous delay to compute the next, e.g. to implement exponential backoff

retriable

Function to determine whether a failure is retriable or not, defaults to retry every NonFatal. A failed stream is immediately returned when a non-retriable failure is encountered

Attributes

Source
Stream.scala
def sleep[F[_]](d: FiniteDuration)(implicit t: Temporal[F]): Stream[F, Unit]

A single-element Stream that waits for the duration d before emitting unit.

A single-element Stream that waits for the duration d before emitting unit.

Attributes

Source
Stream.scala
def sleep_[F[_]](d: FiniteDuration)(implicit t: Temporal[F]): Stream[F, Nothing]

Alias for sleep(d).drain.

Alias for sleep(d).drain. Often used in conjunction with ++ (i.e., sleep_(..) ++ s) as a more performant version of sleep(..) >> s.

Attributes

Source
Stream.scala
def supervise[F[_], A](fa: F[A])(implicit F: Spawn[F]): Stream[F, Fiber[F, Throwable, A]]

Starts the supplied task and cancels it as finalization of the returned stream.

Starts the supplied task and cancels it as finalization of the returned stream.

Attributes

Source
Stream.scala
def suspend[F[_], O](s: => Stream[F, O]): Stream[F, O]

Returns a stream that evaluates the supplied by-name each time the stream is used, allowing use of a mutable value in stream computations.

Returns a stream that evaluates the supplied by-name each time the stream is used, allowing use of a mutable value in stream computations.

Note: it's generally easier to reason about such computations using effectful values. That is, allocate the mutable value in an effect and then use Stream.eval(fa).flatMap { a => ??? }.

Attributes

Example

scala> Stream.suspend {
    |   val digest = java.security.MessageDigest.getInstance("SHA-256")
    |   val bytes: Stream[Pure,Byte] = ???
    |   bytes.chunks.fold(digest) { (d,c) => d.update(c.toBytes.values); d }
    | }
Source
Stream.scala
def unfold[F[x], S, O](s: S)(f: S => Option[(O, S)]): Stream[F, O]

Creates a stream by successively applying f until a None is returned, emitting each output O and using each output S as input to the next invocation of f.

Creates a stream by successively applying f until a None is returned, emitting each output O and using each output S as input to the next invocation of f.

Attributes

Example

scala> Stream.unfold(0)(i => if (i < 5) Some(i -> (i+1)) else None).toList
res0: List[Int] = List(0, 1, 2, 3, 4)
Source
Stream.scala
def unfoldChunk[F[x], S, O](s: S)(f: S => Option[(Chunk[O], S)]): Stream[F, O]

Like unfold but each invocation of f provides a chunk of output.

Like unfold but each invocation of f provides a chunk of output.

Attributes

Example

scala> Stream.unfoldChunk(0)(i => if (i < 5) Some(Chunk.from(List.fill(i)(i)) -> (i+1)) else None).toList
res0: List[Int] = List(1, 2, 2, 3, 3, 3, 4, 4, 4, 4)
Source
Stream.scala
def unfoldChunkEval[F[_], S, O](s: S)(f: S => F[Option[(Chunk[O], S)]]): Stream[F, O]

Like unfoldChunk, but takes an effectful function.

Like unfoldChunk, but takes an effectful function.

Attributes

Source
Stream.scala
def unfoldEval[F[_], S, O](s: S)(f: S => F[Option[(O, S)]]): Stream[F, O]

Like unfold, but takes an effectful function.

Like unfold, but takes an effectful function.

Attributes

Source
Stream.scala
def unfoldLoop[F <: (Pure), S, O](start: S)(f: S => (O, Option[S])): Stream[F, O]

Creates a stream by successively applying f to a S, emitting each output O and using each output S as input to the next invocation of f if it is Some, or terminating on None

Creates a stream by successively applying f to a S, emitting each output O and using each output S as input to the next invocation of f if it is Some, or terminating on None

Attributes

Example

scala> Stream.unfoldLoop(0)(i => (i, if (i < 5) Some(i+1) else None)).toList
res0: List[Int] = List(0, 1, 2, 3, 4, 5)
Source
Stream.scala
def unfoldLoopEval[F[_], S, O](start: S)(f: S => F[(O, Option[S])]): Stream[F, O]

Like unfoldLoop, but takes an effectful function.

Like unfoldLoop, but takes an effectful function.

Attributes

Source
Stream.scala

Deprecated methods

def eval_[F[_], A](fa: F[A]): Stream[F, Nothing]

Creates a stream that evaluates the supplied fa for its effect, discarding the output value.

Creates a stream that evaluates the supplied fa for its effect, discarding the output value. As a result, the returned stream emits no elements and hence has output type Nothing.

Alias for eval(fa).drain.

Attributes

Deprecated
true
Source
Stream.scala

Concrete fields

val empty: Stream[Pure, Nothing]

Empty pure stream.

Empty pure stream.

Attributes

Source
Stream.scala
val unit: Stream[Pure, Unit]

A pure stream that just emits the unit value once and ends.

A pure stream that just emits the unit value once and ends.

Attributes

Source
Stream.scala

Implicits

Implicits

final implicit def FallibleOps[O](self: Stream[Fallible, O]): FallibleOps[O]

Provides syntax for fallible streams.

Provides syntax for fallible streams.

Attributes

Source
Stream.scala
final implicit def IdOps[O](self: Stream[Id, O]): IdOps[O]

Provides syntax for pure pipes based on cats.Id.

Provides syntax for pure pipes based on cats.Id.

Attributes

Source
Stream.scala
final implicit def InvariantOps[F[_], O](self: Stream[F, O]): InvariantOps[F, O]

A view of Stream that removes the variance from the type parameters.

A view of Stream that removes the variance from the type parameters. This allows defining syntax in which the type parameters appear in contravariant (i.e. input) position, which would fail to compile if defined as instance methods.

Attributes

Source
Stream.scala
final implicit def NestedStreamOps[F[_], O](outer: Stream[F, Stream[F, O]]): NestedStreamOps[F, O]

Provides syntax for streams of streams.

Provides syntax for streams of streams.

Attributes

Source
Stream.scala
final implicit def NothingStreamOps[F[_]](self: Stream[F, Nothing]): NothingStreamOps[F]

Attributes

Source
Stream.scala
final implicit def OptionStreamOps[F[_], O](self: Stream[F, Option[O]]): OptionStreamOps[F, O]

Attributes

Source
Stream.scala
final implicit def PipeOps[F[_], I, O](self: (F, I) => O): PipeOps[F, I, O]

Provides operations on effectful pipes for syntactic convenience.

Provides operations on effectful pipes for syntactic convenience.

Attributes

Source
Stream.scala
final implicit def PureOps[O](self: Stream[Pure, O]): PureOps[O]

Provides syntax for pure streams.

Provides syntax for pure streams.

Attributes

Source
Stream.scala
final implicit def PurePipe2Ops[I, I2, O](self: (Pure, I, I2) => O): PurePipe2Ops[I, I2, O]

Provides operations on pure pipes for syntactic convenience.

Provides operations on pure pipes for syntactic convenience.

Attributes

Source
Stream.scala
final implicit def PurePipeOps[I, O](self: (Pure, I) => O): PurePipeOps[I, O]

Provides operations on pure pipes for syntactic convenience.

Provides operations on pure pipes for syntactic convenience.

Attributes

Source
Stream.scala
implicit def alignInstance[F[_]]: Align[[_] =>> Stream[F, _$225]]

Align instance for Stream.

Align instance for Stream. * @example

scala> import cats.syntax.all._
scala> Stream(1,2,3).align(Stream("A","B","C","D","E")).toList
res0: List[cats.data.Ior[Int,String]] = List(Both(1,A), Both(2,B), Both(3,C), Right(D), Right(E))

Attributes

Source
Stream.scala
implicit def deferInstance[F[_]]: Defer[[_] =>> Stream[F, _$250]]

Defer instance for Stream

Defer instance for Stream

Attributes

Source
Stream.scala
implicit def functionKInstance[F[_]]: FunctionK[F, [_] =>> Stream[F, _$244]]

FunctionK instance for F ~> Stream[F, *]

FunctionK instance for F ~> Stream[F, *]

Attributes

Example

scala> import cats.Id
scala> Stream.functionKInstance[Id](42).compile.toList
res0: cats.Id[List[Int]] = List(42)
Source
Stream.scala
implicit def functorFilterInstance[F[_]]: FunctorFilter[[_] =>> Stream[F, _$238]]

FunctorFilter instance for Stream.

FunctorFilter instance for Stream.

Attributes

Example

scala> import cats.syntax.all._, scala.util._
scala> Stream("1", "2", "NaN").mapFilter(s => Try(s.toInt).toOption).toList
res0: List[Int] = List(1, 2)
Source
Stream.scala
implicit def monadErrorInstance[F[_]](implicit ev: ApplicativeError[F, Throwable]): MonadError[[_] =>> Stream[F, _$221], Throwable]

MonadError instance for Stream.

MonadError instance for Stream.

Attributes

Example

scala> import cats.syntax.all._
scala> Stream(1, -2, 3).fproduct(_.abs).toList
res0: List[(Int, Int)] = List((1,1), (-2,2), (3,3))
Source
Stream.scala
implicit def monoidInstance[F[_], O]: Monoid[Stream[F, O]]

Monoid instance for Stream.

Monoid instance for Stream.

Attributes

Source
Stream.scala
implicit def monoidKInstance[F[_]]: MonoidK[[_] =>> Stream[F, _$247]]

Attributes

Source
Stream.scala

Inherited implicits

implicit def monadInstance[F[_]]: Monad[[_] =>> Stream[F, _$253]]

Attributes

Inherited from:
StreamLowPriority (hidden)
Source
Stream.scala