object Iterant extends IterantInstances with Serializable
Defines the standard Iterant builders.
- Alphabetic
- By Inheritance
- Iterant
- Serializable
- Serializable
- IterantInstances
- IterantInstances1
- IterantInstances0
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
class
CatsAsyncInstances[F[_]] extends IterantInstances1.CatsSyncInstances[F] with Async[[α]Iterant[F, α]]
Provides the
cats.effect.Asyncinstance for Iterant.Provides the
cats.effect.Asyncinstance for Iterant.- Definition Classes
- IterantInstances1
-
class
CatsSyncInstances[F[_]] extends Sync[[α]Iterant[F, α]] with MonoidK[[α]Iterant[F, α]] with CoflatMap[[α]Iterant[F, α]]
Provides the
cats.effect.Syncinstance for Iterant.Provides the
cats.effect.Syncinstance for Iterant.- Definition Classes
- IterantInstances0
-
final
case class
Halt[F[_], A](e: Option[Throwable]) extends Iterant[F, A] with Product with Serializable
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.
Haltis 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.- e
is an error to signal at the end of the stream, or
Nonein case the stream has completed normally
-
final
case class
Last[F[_], A](item: A) extends Iterant[F, A] with Product with Serializable
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 monadicF[_]and to short-circuit operations such as concatenation andflatMap.- item
is the last element being signaled, after which the consumer can stop the iteration
-
final
case class
Next[F[_], A](item: A, rest: F[Iterant[F, A]], stop: F[Unit]) extends Iterant[F, A] with Product with Serializable
The Next state of the Iterant represents a
head/restcons pair, where theheadis a strict value.The Next state of the Iterant represents a
head/restcons pair, where theheadis a strict value.Note the
headbeing a strict value means that it is already known, whereas therestis meant to be lazy and can have asynchronous behavior as well, depending on theFtype used.See NextCursor for a state where the head is a strict immutable list.
- item
is the current element to be signaled
- rest
is the next state in the sequence that will produce the rest of the stream when evaluated
- stop
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)
-
final
case class
NextBatch[F[_], A](batch: Batch[A], rest: F[Iterant[F, A]], stop: F[Unit]) extends Iterant[F, A] with Product with Serializable
The NextBatch state of the Iterant represents an
batch/restcons pair, wherebatchis an Iterable type that can generate a whole batch of elements.The NextBatch state of the Iterant represents an
batch/restcons pair, wherebatchis an Iterable type that can generate a whole batch of elements.- batch
is a Iterable type that can generate elements by traversing a collection, a standard array or any
Iterable- rest
is the next state in the sequence that will produce the rest of the stream when evaluated
- stop
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)
-
final
case class
NextCursor[F[_], A](cursor: BatchCursor[A], rest: F[Iterant[F, A]], stop: F[Unit]) extends Iterant[F, A] with Product with Serializable
The NextCursor state of the Iterant represents an
batch/restcons pair, wherebatchis an Iterator type that can generate a whole batch of elements.The NextCursor state of the Iterant represents an
batch/restcons pair, wherebatchis 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.
- cursor
is an Iterator type that can generate elements by traversing a collection, a standard array or any
Iterator- rest
is the next state in the sequence that will produce the rest of the stream when evaluated
- stop
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)
-
final
case class
Suspend[F[_], A](rest: F[Iterant[F, A]], stop: F[Unit]) extends Iterant[F, A] with Product with Serializable
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
Fcontext. It is useful to delay the evaluation of a stream by deferring toF.- rest
is the next state in the sequence that will produce the rest of the stream when evaluated
- stop
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)
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
apply[F[_]](implicit F: From[F]): Builders
Returns an IterantBuilders instance for the specified
Fmonadic type that can be used to build Iterant instances.Returns an IterantBuilders instance for the specified
Fmonadic type that can be used to build Iterant instances.Example:
Iterant[Task].range(0, 10)
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
bracket[F[_], A, B](acquire: F[A])(use: (A) ⇒ Iterant[F, B], release: (A) ⇒ F[Unit])(implicit F: Sync[F]): Iterant[F, B]
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
- acquire
resource to acquire at the start of the stream
- use
function that uses the resource to generate a stream of outputs
- release
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()
-
implicit
def
catsAsyncInstances[F[_]](implicit F: Async[F]): CatsAsyncInstances[F]
Provides the
cats.effect.Asyncinstance for Iterant.Provides the
cats.effect.Asyncinstance for Iterant.- Definition Classes
- IterantInstances1
-
implicit
val
catsInstancesForCoeval: CatsSyncInstances[Coeval]
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.- Definition Classes
- IterantInstances
-
implicit
val
catsInstancesForIO: CatsAsyncInstances[IO]
Provides type class instances for
Iterant[IO, A].Provides type class instances for
Iterant[IO, A].- Definition Classes
- IterantInstances
-
implicit
val
catsInstancesForTask: CatsAsyncInstances[Task]
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.- Definition Classes
- IterantInstances
-
implicit
def
catsSyncInstances[F[_]](implicit F: Sync[F]): CatsSyncInstances[F]
Provides the
cats.effect.Syncinstance for Iterant.Provides the
cats.effect.Syncinstance for Iterant.- Definition Classes
- IterantInstances0
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
defer[F[_], A](fa: ⇒ Iterant[F, A])(implicit F: Sync[F]): Iterant[F, A]
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.
- fa
is the by-name parameter that will generate the stream when evaluated
-
def
empty[F[_], A]: Iterant[F, A]
Returns an empty stream.
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
eval[F[_], A](a: ⇒ A)(implicit F: Sync[F]): Iterant[F, A]
Lifts a non-strict value into the stream context, returning a stream of one element that is lazily evaluated.
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
fromArray[F[_], A](xs: Array[A])(implicit arg0: ClassTag[A], F: Applicative[F]): Iterant[F, A]
Converts any standard
Arrayinto a stream. -
def
fromIndexedSeq[F[_], A](xs: IndexedSeq[A])(implicit F: Applicative[F]): Iterant[F, A]
Converts any Scala
collection.IndexedSeqinto a stream (e.g.Converts any Scala
collection.IndexedSeqinto a stream (e.g.Vector). -
def
fromIterable[F[_], A](xs: Iterable[A])(implicit F: Applicative[F]): Iterant[F, A]
Converts a
scala.collection.Iterableinto a stream. -
def
fromIterator[F[_], A](xs: Iterator[A])(implicit F: Applicative[F]): Iterant[F, A]
Converts a
scala.collection.Iteratorinto a stream. -
def
fromList[F[_], A](xs: LinearSeq[A])(implicit F: Applicative[F]): Iterant[F, A]
Converts any Scala
collection.immutable.LinearSeqinto a stream. -
def
fromSeq[F[_], A](xs: Seq[A])(implicit F: Applicative[F]): Iterant[F, A]
Converts any
scala.collection.Seqinto a stream. -
def
fromStateAction[F[_], S, A](f: (S) ⇒ (A, S))(seed: ⇒ S)(implicit F: Sync[F]): Iterant[F, A]
Given an initial state and a generator function that produces the next state and the next element in the sequence, creates an
Iterantthat keeps generatingNextBatchitems produced by our generator function with defaultrecommendedBatchSize.Given an initial state and a generator function that produces the next state and the next element in the sequence, creates an
Iterantthat keeps generatingNextBatchitems produced by our generator function with defaultrecommendedBatchSize.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)
- See also
fromStateActionL for version supporting
F[_]in result of generator function and seed element
-
def
fromStateActionL[F[_], S, A](f: (S) ⇒ F[(A, S)])(seed: ⇒ F[S])(implicit F: Sync[F]): Iterant[F, A]
Given an initial state and a generator function that produces the next state and the next element in the sequence in
F[_]context, creates anIterantthat keeps generatingNextitems 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 anIterantthat keeps generatingNextitems 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)
- See also
fromStateAction for version without
F[_]context which generatesNextBatchitems
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
haltS[F[_], A](e: Option[Throwable]): Iterant[F, A]
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.
Haltis 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.- e
is an error to signal at the end of the stream, or
Nonein case the stream has completed normally
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
intervalAtFixedRate[F[_]](initialDelay: FiniteDuration, period: FiniteDuration)(implicit F: Async[F], timer: Timer[F]): Iterant[F, Long]
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 providedperiod, thus created iterant tries to emit events spaced by the given time interval, regardless of how long further processing takesThis version of the
intervalAtFixedRateallows specifying aninitialDelaybefore first value is emitted- initialDelay
initial delay before emitting the first value
- period
period between 2 successive emitted values
- timer
is the timer implementation used to generate delays and to fetch the current time
-
def
intervalAtFixedRate[F[_]](period: FiniteDuration)(implicit F: Async[F], timer: Timer[F]): Iterant[F, Long]
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 providedperiod, thus created iterant tries to emit events spaced by the given time interval, regardless of how long further processing takes- period
period between 2 successive emitted values
- timer
is the timer implementation used to generate delays and to fetch the current time
-
def
intervalWithFixedDelay[F[_]](initialDelay: FiniteDuration, delay: FiniteDuration)(implicit F: Async[F], timer: Timer[F]): Iterant[F, Long]
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
periodof time. The givenperiodof time acts as a fixed delay between successive events.- initialDelay
is the delay to wait before emitting the first event
- delay
the time to wait between 2 successive events
- timer
is the timer implementation used to generate delays and to fetch the current time
-
def
intervalWithFixedDelay[F[_]](delay: FiniteDuration)(implicit F: Async[F], timer: Timer[F]): Iterant[F, Long]
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
periodof time. The givenperiodof 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.
- delay
the time to wait between 2 successive events
- timer
is the timer implementation used to generate delays and to fetch the current time
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
lastS[F[_], A](item: A): Iterant[F, A]
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 monadicF[_]and to short-circuit operations such as concatenation andflatMap.- item
is the last element being signaled, after which the consumer can stop the iteration
-
def
liftF[F[_], A](fa: F[A])(implicit F: Applicative[F]): Iterant[F, A]
Lifts a value from monadic context into the stream context, returning a stream of one element
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
nextBatchS[F[_], A](items: Batch[A], rest: F[Iterant[F, A]], stop: F[Unit]): Iterant[F, A]
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/restcons pair, wherebatchis an Iterable type that can generate a whole batch of elements.- items
is a Iterable type that can generate elements by traversing a collection, a standard array or any
Iterable- rest
is the next state in the sequence that will produce the rest of the stream when evaluated
- stop
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)
-
def
nextCursorS[F[_], A](items: BatchCursor[A], rest: F[Iterant[F, A]], stop: F[Unit]): Iterant[F, A]
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/restcons pair, wherebatchis 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.
- items
is an Iterator type that can generate elements by traversing a collection, a standard array or any
Iterator- rest
is the next state in the sequence that will produce the rest of the stream when evaluated
- stop
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)
-
def
nextS[F[_], A](item: A, rest: F[Iterant[F, A]], stop: F[Unit]): Iterant[F, A]
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/restcons pair, where theheadis a strict value.Note the
headbeing a strict value means that it is already known, whereas therestis meant to be lazy and can have asynchronous behavior as well, depending on theFtype used.See NextCursor for a state where the head is a strict immutable list.
- item
is the current element to be signaled
- rest
is the next state in the sequence that will produce the rest of the stream when evaluated
- stop
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)
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
now[F[_], A](a: A): Iterant[F, A]
Lifts a strict value into the stream context, returning a stream of one element.
-
def
pure[F[_], A](a: A): Iterant[F, A]
Alias for now.
-
def
raiseError[F[_], A](ex: Throwable): Iterant[F, A]
Returns an empty stream that ends with an error.
-
def
range[F[_]](from: Int, until: Int, step: Int = 1)(implicit F: Applicative[F]): Iterant[F, Int]
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.
- from
the start value of the stream
- until
the end value of the stream (exclusive from the stream)
- step
the increment value of the tail (must be positive or negative)
- returns
the tail producing values
from, from + step, ...up to, but excludinguntil
-
def
repeat[F[_], A](elems: A*)(implicit F: Sync[F]): Iterant[F, A]
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.
-
def
repeatEval[F[_], A](thunk: ⇒ A)(implicit F: Sync[F]): Iterant[F, A]
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.continuallyExample: infinite sequence of random numbers
import scala.util.Random val randomInts = Iterant[Coeval].repeatEval(Random.nextInt())
-
def
repeatEvalF[F[_], A](fa: F[A])(implicit F: Sync[F]): Iterant[F, A]
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
-
def
suspend[F[_], A](rest: F[Iterant[F, A]])(implicit F: Applicative[F]): Iterant[F, A]
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
Fcontext. It is useful to delay the evaluation of a stream by deferring toF.- rest
is the next state in the sequence that will produce the rest of the stream when evaluated
-
def
suspend[F[_], A](fa: ⇒ Iterant[F, A])(implicit F: Sync[F]): Iterant[F, A]
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.
- fa
is the by-name parameter that will generate the stream when evaluated
-
def
suspendS[F[_], A](rest: F[Iterant[F, A]], stop: F[Unit]): Iterant[F, A]
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
Fcontext. It is useful to delay the evaluation of a stream by deferring toF.- rest
is the next state in the sequence that will produce the rest of the stream when evaluated
- stop
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)
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
tailRecM[F[_], A, B](a: A)(f: (A) ⇒ Iterant[F, Either[A, B]])(implicit F: Sync[F]): Iterant[F, B]
Keeps calling
fand concatenating the resulting iterants for eachscala.util.Leftevent emitted by the source, concatenating the resulting iterants and generating events out ofscala.util.Right[B]values.Keeps calling
fand concatenating the resulting iterants for eachscala.util.Leftevent emitted by the source, concatenating the resulting iterants and generating events out ofscala.util.Right[B]values.Based on Phil Freeman's Stack Safety for Free.
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )