Provides the cats.effect.Async
instance for Iterant.
Provides the cats.effect.Async
instance for Iterant.
Provides the cats.effect.Sync
instance for Iterant.
Provides the cats.effect.Sync
instance for Iterant.
The Halt state of the Iterant represents the completion state of a stream, with an optional exception if an error happened.
The Halt state of the Iterant represents the completion state of a stream, with an optional exception if an error happened.
Halt
is received as a final state in the iteration process.
This state cannot be followed by any other element and
represents the end of the stream.
is an error to signal at the end of the stream,
or None
in case the stream has completed normally
The Last state of the Iterant represents a completion state as an alternative to Halt(None), describing one last element.
The Last state of the Iterant represents a completion state as an alternative to Halt(None), describing one last element.
It is introduced as an optimization, being equivalent to
Next(item, F.pure(Halt(None)), F.unit)
, to avoid extra processing
in the monadic F[_]
and to short-circuit operations such as
concatenation and flatMap
.
is the last element being signaled, after which the consumer can stop the iteration
The Next state
of the Iterant represents a head
/ rest
cons pair, where the head
is a strict value.
The Next state
of the Iterant represents a head
/ rest
cons pair, where the head
is a strict value.
Note the head
being a strict value means that it is
already known, whereas the rest
is meant to be lazy and
can have asynchronous behavior as well, depending on the F
type used.
See NextCursor for a state where the head is a strict immutable list.
is the current element to be signaled
is the next state in the sequence that will produce the rest of the stream when evaluated
is a computation to be executed in case streaming is stopped prematurely, giving it a chance to do resource cleanup (e.g. close file handles)
The NextBatch state
of the Iterant represents an batch
/ rest
cons pair,
where batch
is an Iterable
type that can generate a whole batch of elements.
The NextBatch state
of the Iterant represents an batch
/ rest
cons pair,
where batch
is an Iterable
type that can generate a whole batch of elements.
is a Iterable
type that can generate elements by traversing a collection,
a standard array or any Iterable
is the next state in the sequence that will produce the rest of the stream when evaluated
is a computation to be executed in case streaming is stopped prematurely, giving it a chance to do resource cleanup (e.g. close file handles)
The NextCursor state
of the Iterant represents an batch
/ rest
cons pair,
where batch
is an Iterator
type that can generate a whole batch of elements.
The NextCursor state
of the Iterant represents an batch
/ rest
cons pair,
where batch
is an Iterator
type that can generate a whole batch of elements.
Useful for doing buffering, or by giving it an empty iterator, useful to postpone the evaluation of the next element.
is an Iterator type
that can generate elements by traversing a collection, a standard
array or any Iterator
is the next state in the sequence that will produce the rest of the stream when evaluated
is a computation to be executed in case streaming is stopped prematurely, giving it a chance to do resource cleanup (e.g. close file handles)
Builds a stream state equivalent with Iterant.NextCursor.
Builds a stream state equivalent with Iterant.NextCursor.
The Suspend state
of the Iterant represents a suspended stream to be
evaluated in the F
context. It is useful to delay the
evaluation of a stream by deferring to F
.
is the next state in the sequence that will produce the rest of the stream when evaluated
is a computation to be executed in case streaming is stopped prematurely, giving it a chance to do resource cleanup (e.g. close file handles)
Returns an IterantBuilders instance for the specified F
monadic type that can be used to build Iterant instances.
Returns an IterantBuilders instance for the specified F
monadic type that can be used to build Iterant instances.
Example:
Iterant[Task].range(0, 10)
Creates a stream that depends on resource allocated by a monadic value, ensuring the resource is released.
Creates a stream that depends on resource allocated by a monadic value, ensuring the resource is released.
Typical use-cases are working with files or network sockets
resource to acquire at the start of the stream
function that uses the resource to generate a stream of outputs
function that releases the acquired resource Example:
val writeLines = Iterant.bracket(IO { new PrintWriter("./lines.txt") })( writer => Iterant[IO] .fromIterator(Iterator.from(1)) .mapEval(i => IO { writer.println(s"Line #$i") }), writer => IO { writer.close() } ) // Write 100 numbered lines to the file // closing the writer when finished writeLines.take(100).completeL.unsafeRunSync()
Provides the cats.effect.Async
instance for Iterant.
Provides the cats.effect.Async
instance for Iterant.
Provides type class instances for Iterant[Coeval, A]
, based on
the default instances provided by
Coeval.catsSync.
Provides type class instances for Iterant[Coeval, A]
, based on
the default instances provided by
Coeval.catsSync.
Provides type class instances for Iterant[IO, A]
.
Provides type class instances for Iterant[IO, A]
.
Provides type class instances for Iterant[Task, A]
, based
on the default instances provided by
Task.catsAsync.
Provides type class instances for Iterant[Task, A]
, based
on the default instances provided by
Task.catsAsync.
Provides the cats.effect.Sync
instance for Iterant.
Provides the cats.effect.Sync
instance for Iterant.
Alias for suspend.
Alias for suspend.
Promote a non-strict value representing a stream to a stream of the same type, effectively delaying its initialisation.
is the by-name parameter that will generate the stream when evaluated
Returns an empty stream.
Lifts a non-strict value into the stream context, returning a stream of one element that is lazily evaluated.
Converts any standard Array
into a stream.
Converts any Scala collection.IndexedSeq
into a stream
(e.g.
Converts any Scala collection.IndexedSeq
into a stream
(e.g. Vector
).
Converts a scala.collection.Iterable
into a stream.
Converts a scala.collection.Iterator
into a stream.
Converts any Scala collection.immutable.LinearSeq
into
a stream.
Converts any scala.collection.Seq
into a stream.
Given an initial state and a generator function that produces the
next state and the next element in the sequence, creates an
Iterant
that keeps generating NextBatch
items produced
by our generator function with default recommendedBatchSize
.
Given an initial state and a generator function that produces the
next state and the next element in the sequence, creates an
Iterant
that keeps generating NextBatch
items produced
by our generator function with default recommendedBatchSize
.
Example:
val f = (x: Int) => (x + 1, x * 2) val seed = 1 val stream = Iterant.fromStateAction[Task, Int, Int](f)(seed) // Yields 2, 3, 5, 9 stream.take(5)
fromStateActionL for version supporting F[_]
in result of generator function and seed element
Given an initial state and a generator function that produces the
next state and the next element in the sequence in F[_]
context, creates an
Iterant
that keeps generating Next
items produced by our generator function.
Given an initial state and a generator function that produces the
next state and the next element in the sequence in F[_]
context, creates an
Iterant
that keeps generating Next
items produced by our generator function.
Example:
val f = (x: Int) => F.pure((x + 1, x * 2)) val seed = F.pure(1) val stream = Iterant.fromStateAction[Task, Int, Int](f)(seed) // Yields 2, 3, 5, 9 stream.take(5)
fromStateAction for version without F[_]
context which generates NextBatch
items
Builds a stream state equivalent with Iterant.Halt.
Builds a stream state equivalent with Iterant.Halt.
The Halt state of the Iterant represents the completion state of a stream, with an optional exception if an error happened.
Halt
is received as a final state in the iteration process.
This state cannot be followed by any other element and
represents the end of the stream.
is an error to signal at the end of the stream,
or None
in case the stream has completed normally
Creates an iterant that emits auto-incremented natural numbers (longs).
Creates an iterant that
emits auto-incremented natural numbers (longs).
at a fixed rate, as given by the specified period
.
The amount of time it takes to process an incoming
value gets subtracted from provided period
, thus
created iterant tries to emit events spaced by the
given time interval, regardless of how long further
processing takes
This version of the intervalAtFixedRate
allows specifying an
initialDelay
before first value is emitted
initial delay before emitting the first value
period between 2 successive emitted values
is the timer implementation used to generate delays and to fetch the current time
Creates an iterant that emits auto-incremented natural numbers (longs).
Creates an iterant that
emits auto-incremented natural numbers (longs).
at a fixed rate, as given by the specified period
.
The amount of time it takes to process an incoming
value gets subtracted from provided period
, thus
created iterant tries to emit events spaced by the
given time interval, regardless of how long further
processing takes
period between 2 successive emitted values
is the timer implementation used to generate delays and to fetch the current time
Creates an iterant that emits auto-incremented natural numbers (longs) spaced by a given time interval.
Creates an iterant that
emits auto-incremented natural numbers (longs) spaced
by a given time interval. Starts from 0 with no delay,
after which it emits incremented numbers spaced by the
period
of time. The given period
of time acts as a
fixed delay between successive events.
is the delay to wait before emitting the first event
the time to wait between 2 successive events
is the timer implementation used to generate delays and to fetch the current time
Creates an iterant that emits auto-incremented natural numbers (longs) spaced by a given time interval.
Creates an iterant that
emits auto-incremented natural numbers (longs) spaced
by a given time interval. Starts from 0 with no delay,
after which it emits incremented numbers spaced by the
period
of time. The given period
of time acts as a
fixed delay between successive events.
Without having an initial delay specified, this overload will immediately emit the first item, without any delays.
the time to wait between 2 successive events
is the timer implementation used to generate delays and to fetch the current time
Builds a stream state equivalent with Iterant.Last.
Builds a stream state equivalent with Iterant.Last.
The Last state of the Iterant represents a completion state as an alternative to Halt(None), describing one last element.
It is introduced as an optimization, being equivalent to
Next(item, F.pure(Halt(None)), F.unit)
, to avoid extra processing
in the monadic F[_]
and to short-circuit operations such as
concatenation and flatMap
.
is the last element being signaled, after which the consumer can stop the iteration
Lifts a value from monadic context into the stream context, returning a stream of one element
Builds a stream state equivalent with Iterant.NextBatch.
Builds a stream state equivalent with Iterant.NextBatch.
The NextBatch state
of the Iterant represents an batch
/ rest
cons pair,
where batch
is an Iterable
type that can generate a whole batch of elements.
is a Iterable
type that can generate elements by traversing a collection,
a standard array or any Iterable
is the next state in the sequence that will produce the rest of the stream when evaluated
is a computation to be executed in case streaming is stopped prematurely, giving it a chance to do resource cleanup (e.g. close file handles)
Builds a stream state equivalent with Iterant.NextCursor.
Builds a stream state equivalent with Iterant.NextCursor.
The NextCursor state
of the Iterant represents an batch
/ rest
cons pair,
where batch
is an Iterator
type that can generate a whole batch of elements.
Useful for doing buffering, or by giving it an empty iterator, useful to postpone the evaluation of the next element.
is an Iterator type
that can generate elements by traversing a collection, a standard
array or any Iterator
is the next state in the sequence that will produce the rest of the stream when evaluated
is a computation to be executed in case streaming is stopped prematurely, giving it a chance to do resource cleanup (e.g. close file handles)
Builds a stream state equivalent with Iterant.Next.
Builds a stream state equivalent with Iterant.Next.
The Next state
of the Iterant represents a head
/ rest
cons pair, where the head
is a strict value.
Note the head
being a strict value means that it is
already known, whereas the rest
is meant to be lazy and
can have asynchronous behavior as well, depending on the F
type used.
See NextCursor for a state where the head is a strict immutable list.
is the current element to be signaled
is the next state in the sequence that will produce the rest of the stream when evaluated
is a computation to be executed in case streaming is stopped prematurely, giving it a chance to do resource cleanup (e.g. close file handles)
Lifts a strict value into the stream context, returning a stream of one element.
Alias for now.
Returns an empty stream that ends with an error.
Builds a stream that on evaluation will produce equally spaced values in some integer interval.
Builds a stream that on evaluation will produce equally spaced values in some integer interval.
the start value of the stream
the end value of the stream (exclusive from the stream)
the increment value of the tail (must be positive or negative)
the tail producing values from, from + step, ...
up
to, but excluding until
Builds a stream that repeats the items provided in argument.
Builds a stream that repeats the items provided in argument.
It terminates either on error or if the source is empty.
Builds a stream that suspends provided thunk and evaluates it indefinitely on-demand.
Builds a stream that suspends provided thunk and evaluates it indefinitely on-demand.
The stream will only terminate if evaluation throws an exception
Referentially transparent alternative to Iterator.continually
Example: infinite sequence of random numbers
import scala.util.Random val randomInts = Iterant[Coeval].repeatEval(Random.nextInt())
Builds a stream that evaluates provided effectful values indefinitely.
Builds a stream that evaluates provided effectful values indefinitely.
The stream will only terminate if an error is raised in F context
Defers the stream generation to the underlying evaluation context (e.g.
Defers the stream generation to the underlying evaluation
context (e.g. Task
, Coeval
, IO
, etc), building a reference
equivalent with Iterant.Suspend.
The Suspend state
of the Iterant represents a suspended stream to be
evaluated in the F
context. It is useful to delay the
evaluation of a stream by deferring to F
.
is the next state in the sequence that will produce the rest of the stream when evaluated
Promote a non-strict value representing a stream to a stream of the same type, effectively delaying its initialisation.
Promote a non-strict value representing a stream to a stream of the same type, effectively delaying its initialisation.
is the by-name parameter that will generate the stream when evaluated
Builds a stream state equivalent with Iterant.NextCursor.
Builds a stream state equivalent with Iterant.NextCursor.
The Suspend state
of the Iterant represents a suspended stream to be
evaluated in the F
context. It is useful to delay the
evaluation of a stream by deferring to F
.
is the next state in the sequence that will produce the rest of the stream when evaluated
is a computation to be executed in case streaming is stopped prematurely, giving it a chance to do resource cleanup (e.g. close file handles)
Keeps calling f
and concatenating the resulting iterants for
each scala.util.Left
event emitted by the source,
concatenating the resulting iterants and generating
events out of scala.util.Right[B]
values.
Keeps calling f
and concatenating the resulting iterants for
each scala.util.Left
event emitted by the source,
concatenating the resulting iterants and generating
events out of scala.util.Right[B]
values.
Based on Phil Freeman's Stack Safety for Free.
Defines the standard Iterant builders.