package tail
- Alphabetic
- Public
- All
Type Members
-
sealed abstract
class
Iterant[F[_], A] extends Product with Serializable
The
Iterantis a type that describes lazy, possibly asynchronous streaming of elements using a pull-based protocol.The
Iterantis a type that describes lazy, possibly asynchronous streaming of elements using a pull-based protocol.It is similar somewhat in spirit to Scala's own
collection.immutable.Streamand with Java'sIterable, except that it is more composable and more flexible due to evaluation being controlled by anF[_]monadic type that you have to supply (like Task, Coeval orcats.effect.IO) which will control the evaluation. In other words, thisIteranttype is capable of strict or lazy, synchronous or asynchronous evaluation.Consumption of an
Iteranthappens typically in a loop where the current step represents either a signal that the stream is over, or a (head, rest) pair, very similar in spirit to Scala's standardListorIterable.The type is an ADT, meaning a composite of the following types:
- Next which signals a single strict
element, the
headand arestrepresenting the rest of the stream - NextBatch is a variation on
Nextfor signaling a whole batch of elements by means of a Batch, a type that's similar with Scala'sIterable, along with therestof the stream. - NextCursor is a variation on
Nextfor signaling a whole strict batch of elements as a traversable BatchCursor, a type that's similar with Scala'sIterator, along with therestof the stream. - Suspend is for suspending the evaluation of a stream.
- Halt represents an empty stream, signaling the end, either in success or in error.
- Last represents a one-element
stream, where
Last(item)as an optimisation onNext(item, F.pure(Halt(None)), F.unit).
Parametric Polymorphism
The
Iteranttype accepts as type parameter anFmonadic type that is used to control how evaluation happens. For example you can use Task, in which case the streaming can have asynchronous behavior, or you can use Coeval in which case it can behave like a normal, synchronousIterable.As restriction, this
F[_]type used should be stack safe inmapandflatMap, otherwise you might get stack-overflow exceptions. This is why in general the type class required forFiscats.effect.Sync.When building instances, type
F[_]which handles the evaluation needs to be specified upfront. Example:import cats.effect.IO import monix.eval.{Task, Coeval} // Builds an Iterant powered by Monix's Task Iterant[Task].of(1, 2, 3) // Builds an Iterant powered by Monix's Coeval Iterant[Coeval].of(1, 2, 3) // Builds an Iterant powered by Cats's IO Iterant[IO].of(1, 2, 3)
You'll usually pick between
Task,CoevalorIOfor your needs.Attribution
This type was inspired by the
Streamingtype in the Typelevel Cats library (later moved to Dogs), originally committed in Cats by Erik Osheim. It was also inspired by other push-based streaming abstractions, like theIterateeorIAsyncEnumerable.- F
is the data type that controls evaluation; note that it must be stack-safe in its
mapandflatMapoperations- A
is the type of the elements produced by this Iterant
- Next which signals a single strict
element, the
-
class
IterantBuilders[F[_]] extends AnyRef
Class defining curried
Iterantbuilders, relieving the user from specifying theAparameter explicitly.Class defining curried
Iterantbuilders, relieving the user from specifying theAparameter explicitly.So instead of having to do:
Iterant.now[Task, Int](1)
You can do:
Iterant[Task].now(1) -
class
IterantBuildersApplicative[F[_]] extends IterantBuilders[F]
Class defining curried
Iterantbuilders for data types that implementcats.Applicative.Class defining curried
Iterantbuilders for data types that implementcats.Applicative.So instead of having to do:
Iterant.of[Task, Int](1, 2, 3)
You can do:
Iterant[Task].now(1, 2, 3)
-
class
IterantBuildersAsync[F[_]] extends IterantBuildersSync[F]
Class defining curried
Iterantbuilders for data types that implementcats.effect.Async.Class defining curried
Iterantbuilders for data types that implementcats.effect.Async.So instead of having to do:
Iterant.intervalAtFixedRate[Task](1.second)You can do:
Iterant[Task].intervalAtFixedRate(1.second) -
class
IterantBuildersSync[F[_]] extends IterantBuildersApplicative[F]
Class defining curried
Iterantbuilders for data types that implementcats.effect.Sync.Class defining curried
Iterantbuilders for data types that implementcats.effect.Sync.So instead of having to do:
Iterant.eval[Task, Int](1 + 1)
You can do:
Iterant[Task].eval(1 + 1)
Value Members
-
object
Iterant extends IterantInstances with Serializable
Defines the standard Iterant builders.
- object IterantBuilders