sealed abstract class Eager[+A] extends Coeval[A] with Product
The Eager type represents a strict, already evaluated result
of a Coeval that either resulted in success, wrapped in a
Now, or in an error, wrapped in an Error.
It's the moral equivalent of scala.util.Try, except that
application of functions such as map and flatMap produces
Coeval references that are still lazily evaluated.
- Self Type
- Eager[A]
- Alphabetic
- By Inheritance
- Eager
- Product
- Equals
- Coeval
- Serializable
- Serializable
- Function0
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Abstract Value Members
Concrete 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(): A
Evaluates the underlying computation and returns the result.
Evaluates the underlying computation and returns the result.
NOTE: this can throw exceptions.
// For didactic purposes, don't do shared vars at home :-) var i = 0 val fa = Coeval { i += 1; i } fa() //=> 1 fa() //=> 2 fa() //=> 3
- Definition Classes
- Coeval → Function0
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
final
def
attempt: Coeval[Either[Throwable, A]]
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 anEithervalue, we can handle those errors inflatMaptransformations.Also see materialize for working with Scala's Try or transformWith for an alternative.
- Definition Classes
- Coeval
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
dematerialize[B](implicit ev: <:<[A, Try[B]]): Coeval[B]
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- Definition Classes
- Coeval
-
final
def
doOnFinish(f: (Option[Throwable]) ⇒ Coeval[Unit]): Coeval[A]
Returns a new
Coevalin whichfis scheduled to be run on completion.Returns a new
Coevalin whichfis scheduled to be run on completion. This would typically be used to release any resources acquired by thisCoeval.- Definition Classes
- Coeval
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
failed: Coeval[Throwable]
Returns a failed projection of this coeval.
Returns a failed projection of this coeval.
The failed projection is a
Coevalholding a value of typeThrowable, emitting the error yielded by the source, in case the source fails, otherwise if the source succeeds the result will fail with aNoSuchElementException.- Definition Classes
- Coeval
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
flatMap[B](f: (A) ⇒ Coeval[B]): Coeval[B]
Creates a new
Coevalby 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
Coevalby 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
flatMapis 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) }
- Definition Classes
- Coeval
-
final
def
flatten[B](implicit ev: <:<[A, Coeval[B]]): Coeval[B]
Given a source Coeval that emits another Coeval, this function flattens the result, returning a Coeval equivalent to the emitted Coeval by the source.
-
final
def
foreach(f: (A) ⇒ Unit): Unit
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.
- Definition Classes
- Coeval
-
final
def
foreachL(f: (A) ⇒ Unit): Coeval[Unit]
Returns a new task that upon evaluation will execute the given function for the generated element, transforming the source into a
Coeval[Unit]. -
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isError: Boolean
Returns true if result is an error.
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
isSuccess: Boolean
Returns true if value is a successful one.
-
final
def
map[B](f: (A) ⇒ B): Coeval[B]
Returns a new
Coevalthat applies the mapping function to the element emitted by the source. -
final
def
materialize: Coeval[Try[A]]
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.
- Definition Classes
- Coeval
-
final
def
memoize: Coeval[A]
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.
- Definition Classes
- Coeval
- See also
memoizeOnSuccess for a version that only caches successful results
-
final
def
memoizeOnSuccess: Coeval[A]
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.
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
onErrorFallbackTo[B >: A](that: Coeval[B]): Coeval[B]
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.
- Definition Classes
- Coeval
-
final
def
onErrorHandle[U >: A](f: (Throwable) ⇒ U): Coeval[U]
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.
- Definition Classes
- Coeval
-
final
def
onErrorHandleWith[B >: A](f: (Throwable) ⇒ Coeval[B]): Coeval[B]
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.
- Definition Classes
- Coeval
-
final
def
onErrorRecover[U >: A](pf: PartialFunction[Throwable, U]): Coeval[U]
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.
- Definition Classes
- Coeval
-
final
def
onErrorRecoverWith[B >: A](pf: PartialFunction[Throwable, Coeval[B]]): Coeval[B]
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.
- Definition Classes
- Coeval
-
final
def
onErrorRestart(maxRetries: Long): Coeval[A]
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.- Definition Classes
- Coeval
-
final
def
onErrorRestartIf(p: (Throwable) ⇒ Boolean): Coeval[A]
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.- Definition Classes
- Coeval
-
def
productIterator: Iterator[Any]
- Definition Classes
- Product
-
def
productPrefix: String
- Definition Classes
- Product
-
final
def
restartUntil(p: (A) ⇒ Boolean): Coeval[A]
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.
- Definition Classes
- Coeval
-
def
run: Eager[A]
Evaluates the underlying computation, reducing this
Coevalto a Coeval.Eager value, with successful results being signaled with Coeval.Now and failures with Coeval.Error.Evaluates the underlying computation, reducing this
Coevalto 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).
- Definition Classes
- Coeval
-
def
runAttempt: Either[Throwable, A]
Evaluates the underlying computation and returns the result or any triggered errors as a Scala
Either, whereRight(_)is for successful values andLeft(_)is for thrown errors.Evaluates the underlying computation and returns the result or any triggered errors as a Scala
Either, whereRight(_)is for successful values andLeft(_)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).
- Definition Classes
- Coeval
-
def
runTry: Try[A]
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).
- Definition Classes
- Coeval
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
- final def task: Task[A]
-
final
def
toEither: Either[Throwable, A]
Converts this
Eagervalue into a scala.Either. -
final
def
toEval: Eval[A]
Converts the source Coeval into a
cats.Eval. -
final
def
toIO: IO[A]
Converts the source Coeval into a
cats.effect.IO. -
def
toString(): String
- Definition Classes
- Coeval → Function0 → AnyRef → Any
-
final
def
toTry: Try[A]
Converts this
Eagervalue into a scala.util.Try. -
final
def
transform[R](fa: (A) ⇒ R, fe: (Throwable) ⇒ R): Coeval[R]
Creates a new
Coevalby 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
Coevalby 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))
- fa
function that transforms a successful result of the receiver
- fe
function that transforms an error of the receiver
- Definition Classes
- Coeval
-
final
def
transformWith[R](fa: (A) ⇒ Coeval[R], fe: (Throwable) ⇒ Coeval[R]): Coeval[R]
Creates a new
Coevalby 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
Coevalby 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)) )
- fa
function that transforms a successful result of the receiver
- fe
function that transforms an error of the receiver
- Definition Classes
- Coeval
-
def
value: A
Evaluates the underlying computation and returns the result.
-
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( ... )
-
final
def
zip[B](that: Coeval[B]): Coeval[(A, B)]
Zips the values of
thisandthatcoeval, and creates a new coeval that will emit the tuple of their results.Zips the values of
thisandthatcoeval, and creates a new coeval that will emit the tuple of their results.- Definition Classes
- Coeval
-
final
def
zipMap[B, C](that: Coeval[B])(f: (A, B) ⇒ C): Coeval[C]
Zips the values of
thisandthatand applies the given mapping function on their results.Zips the values of
thisandthatand applies the given mapping function on their results.- Definition Classes
- Coeval