Evaluates the underlying computation and returns the result.
Creates a new Coeval that will expose any triggered error from the source.
Creates a new Coeval that will expose any triggered error from the source.
val fa: Coeval[Int] = Coeval.raiseError[Int](new DummyException("dummy")) val fe: Coeval[Either[Throwable, Int]] = fa.attempt fe.flatMap { case Left(_) => Int.MaxValue case Right(v) => v }
By exposing errors by lifting the Coeval
's result into an
Either
value, we can handle those errors in flatMap
transformations.
Also see materialize for working with Scala's Try or transformWith for an alternative.
Dematerializes the source's result from a Try
.
Dematerializes the source's result from a Try
.
This equivalence always holds:
scala
fa.materialize.dematerialize <-> fa
Returns a new Coeval
in which f
is scheduled to be run on completion.
Returns a new Coeval
in which f
is scheduled to be run on completion.
This would typically be used to release any resources acquired by this
Coeval
.
Returns a failed projection of this coeval.
Returns a failed projection of this coeval.
The failed projection is a Coeval
holding a value of type Throwable
,
emitting the error yielded by the source, in case the source fails,
otherwise if the source succeeds the result will fail with a
NoSuchElementException
.
Creates a new Coeval
by applying a function to the successful result
of the source, and returns a new instance equivalent
to the result of the function.
Creates a new Coeval
by applying a function to the successful result
of the source, and returns a new instance equivalent
to the result of the function.
The application of flatMap
is always lazy and because of the
implementation it is memory safe and thus it can be used in
recursive loops.
Sample:
def randomEven: Coeval[Int] = Coeval(Random.nextInt()).flatMap { x => if (x < 0 || x % 2 == 1) randomEven // retry else Coeval.now(x) }
Given a source Coeval that emits another Coeval, this function flattens the result, returning a Coeval equivalent to the emitted Coeval by the source.
Triggers the evaluation of the source, executing the given function for the generated element.
Triggers the evaluation of the source, executing the given function for the generated element.
The application of this function has strict behavior, as the coeval is immediately executed.
Returns a new task that upon evaluation will execute
the given function for the generated element,
transforming the source into a Coeval[Unit]
.
Returns a new Coeval that applies the mapping function to the element emitted by the source.
Creates a new Coeval that will expose any triggered error from the source.
Creates a new Coeval that will expose any triggered error from the source.
Also see attempt for working with Scala's Either or transformWith for an alternative.
Memoizes (caches) the result of the source and reuses it on
subsequent invocations of value
.
Memoizes (caches) the result of the source and reuses it on
subsequent invocations of value
.
The resulting coeval will be idempotent, meaning that evaluating the resulting coeval multiple times will have the same effect as evaluating it once.
memoizeOnSuccess for a version that only caches successful results
Memoizes (cache) the successful result of the source
and reuses it on subsequent invocations of value
.
Memoizes (cache) the successful result of the source
and reuses it on subsequent invocations of value
.
Thrown exceptions are not cached.
The resulting coeval will be idempotent, but only if the result is successful.
Creates a new coeval that in case of error will fallback to the given backup coeval.
Creates a new coeval that in case of error will fallback to the given backup coeval.
Creates a new coeval that will handle any matching throwable that this coeval might emit.
Creates a new coeval that will handle any matching throwable that this coeval might emit.
See onErrorRecover for the version that takes a partial function.
Creates a new coeval that will handle any matching throwable that this coeval might emit by executing another coeval.
Creates a new coeval that will handle any matching throwable that this coeval might emit by executing another coeval.
See onErrorRecoverWith for the version that takes a partial function.
Creates a new coeval that on error will try to map the error to another value using the provided partial function.
Creates a new coeval that on error will try to map the error to another value using the provided partial function.
See onErrorHandle for the version that takes a total function.
Creates a new coeval that will try recovering from an error by matching it with another coeval using the given partial function.
Creates a new coeval that will try recovering from an error by matching it with another coeval using the given partial function.
See onErrorHandleWith for the version that takes a total function.
Creates a new coeval that in case of error will retry executing the source again and again, until it succeeds.
Creates a new coeval that in case of error will retry executing the source again and again, until it succeeds.
In case of continuous failure the total number of executions
will be maxRetries + 1
.
Creates a new coeval that in case of error will retry executing the source again and again, until it succeeds.
Creates a new coeval that in case of error will retry executing the source again and again, until it succeeds.
In case of continuous failure the total number of executions
will be maxRetries + 1
.
Given a predicate function, keep retrying the coeval until the function returns true.
Given a predicate function, keep retrying the coeval until the function returns true.
Evaluates the underlying computation, reducing this Coeval
to a Coeval.Eager value, with successful results being
signaled with Coeval.Now and failures with Coeval.Error.
Evaluates the underlying computation, reducing this Coeval
to a Coeval.Eager value, with successful results being
signaled with Coeval.Now and failures with Coeval.Error.
val fa = Coeval.eval(10 * 2) fa.run match { case Coeval.Now(value) => println("Success: " + value) case Coeval.Error(e) => e.printStackTrace() }
See runAttempt for working with Either values and runTry for working with Try values. See apply for a partial function (that may throw exceptions in case of failure).
Evaluates the underlying computation and returns the result or
any triggered errors as a Scala Either
, where Right(_)
is
for successful values and Left(_)
is for thrown errors.
Evaluates the underlying computation and returns the result or
any triggered errors as a Scala Either
, where Right(_)
is
for successful values and Left(_)
is for thrown errors.
val fa = Coeval(10 * 2) fa.runAttempt match { case Right(value) => println("Success: " + value) case Left(e) => e.printStackTrace() }
See run for working with Coeval.Eager values and runTry for working with Try values. See apply for a partial function (that may throw exceptions in case of failure).
Evaluates the underlying computation and returns the
result or any triggered errors as a scala.util.Try
.
Evaluates the underlying computation and returns the
result or any triggered errors as a scala.util.Try
.
val fa = Coeval(10 * 2) fa.runTry match { case Success(value) => println("Success: " + value) case Failure(e) => e.printStackTrace() }
See run for working with Coeval.Eager values and runAttempt for working with Either values. See apply for a partial function (that may throw exceptions in case of failure).
Converts the source Coeval into a cats.Eval
.
Converts the source Coeval into a cats.effect.IO
.
Creates a new Coeval
by applying the 'fa' function to the
successful result of this future, or the 'fe' function to the
potential errors that might happen.
Creates a new Coeval
by applying the 'fa' function to the
successful result of this future, or the 'fe' function to the
potential errors that might happen.
This function is similar with map, except that it can also transform errors and not just successful results.
For example attempt can be expressed in terms of transform
:
source.transform(v => Right(v), e => Left(e))
And materialize too:
source.transform(v => Success(v), e => Failure(e))
function that transforms a successful result of the receiver
function that transforms an error of the receiver
Creates a new Coeval
by applying the 'fa' function to the
successful result of this future, or the 'fe' function to the
potential errors that might happen.
Creates a new Coeval
by applying the 'fa' function to the
successful result of this future, or the 'fe' function to the
potential errors that might happen.
This function is similar with flatMap, except that it can also transform errors and not just successful results.
For example attempt can be expressed in terms of
transformWith
:
source.transformWith( v => Coeval.now(Right(v)), e => Coeval.now(Left(e)) )
function that transforms a successful result of the receiver
function that transforms an error of the receiver
Evaluates the underlying computation and returns the result.
Zips the values of this
and that
coeval, and creates a new coeval
that will emit the tuple of their results.
Zips the values of this
and that
coeval, and creates a new coeval
that will emit the tuple of their results.
Zips the values of this
and that
and applies the given
mapping function on their results.
Zips the values of this
and that
and applies the given
mapping function on their results.
Constructs a lazy Coeval instance.
This type can be used for "lazy" values. In some sense it is equivalent to using a Function0 value.