Packages

sealed abstract class Coeval[+A] extends () ⇒ A with Serializable

Coeval represents lazy computations that can execute synchronously.

Word definition and origin:

  • Having the same age or date of origin; a contemporary; synchronous.
  • From the Latin "coævus": com- ‎("equal") in combination with aevum ‎(aevum, "age").
  • The constructor of Coeval is the dual of an expression that evaluates to an A.

There are three evaluation strategies:

  • Now or Error: for describing strict values, evaluated immediately
  • Once: expressions evaluated a single time
  • Always: expressions evaluated every time the value is needed

The Once and Always are both lazy strategies while Now and Error are eager. Once and Always are distinguished from each other only by memoization: once evaluated Once will save the value to be returned immediately if it is needed again. Always will run its computation every time.

Both Now and Error are represented by the Attempt trait, a sub-type of Coeval that can be used as a replacement for Scala's own Try type.

Coeval supports stack-safe lazy computation via the .map and .flatMap methods, which use an internal trampoline to avoid stack overflows. Computation done within .map and .flatMap is always done lazily, even when applied to a Now instance.

Self Type
Coeval[A]
Source
Coeval.scala
Linear Supertypes
Serializable, Serializable, () ⇒ A, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Coeval
  2. Serializable
  3. Serializable
  4. Function0
  5. AnyRef
  6. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def apply(): A

    Evaluates the underlying computation and returns the result.

    Evaluates the underlying computation and returns the result.

    NOTE: this can throw exceptions.

    Definition Classes
    Coeval → Function0
  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def attempt: Coeval[Either[Throwable, A]]

    Creates a new Coeval that will expose any triggered error from the source.

  7. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  8. def dematerialize[B](implicit ev: <:<[A, Try[B]]): Coeval[B]

    Dematerializes the source's result from a Try.

  9. def doOnFinish(f: (Option[Throwable]) ⇒ Coeval[Unit]): Coeval[A]

    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.

  10. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  11. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  12. def failed: Coeval[Throwable]

    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.

  13. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  14. def flatMap[B](f: (A) ⇒ Coeval[B]): Coeval[B]

    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.

  15. 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.

  16. 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.

  17. 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].

    Returns a new task that upon evaluation will execute the given function for the generated element, transforming the source into a Coeval[Unit].

    Similar in spirit with normal foreach, but lazy, as obviously nothing gets executed at this point.

  18. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  19. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  20. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  21. def map[B](f: (A) ⇒ B): Coeval[B]

    Returns a new Coeval that applies the mapping function to the element emitted by the source.

  22. def materialize: Coeval[Try[A]]

    Creates a new Coeval that will expose any triggered error from the source.

  23. 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.

    See also

    memoizeOnSuccess for a version that only caches successful results

  24. 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.

    See also

    memoize for a version that caches both successful results and failures

  25. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  26. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  27. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  28. 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.

  29. 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.

  30. 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.

  31. 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.

  32. 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.

  33. 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.

  34. 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.

  35. def restartUntil(p: (A) ⇒ Boolean): Coeval[A]

    Given a predicate function, keep retrying the coeval until the function returns true.

  36. def run: Either[Throwable, A]

    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.

  37. def runAttempt: Attempt[A]

    Evaluates the underlying computation and returns the result or any triggered errors as a Coeval.Attempt.

  38. def runTry: Try[A]

    Evaluates the underlying computation and returns the result or any triggered errors as a scala.util.Try.

  39. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  40. def task: Task[A]

    Converts the source Coeval into a Task.

  41. def toString(): String
    Definition Classes
    Function0 → AnyRef → Any
  42. def transform[R](fa: (A) ⇒ R, fe: (Throwable) ⇒ R): Coeval[R]

    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.

    fa

    function that transforms a successful result of the receiver

    fe

    function that transforms an error of the receiver

  43. def transformWith[R](fa: (A) ⇒ Coeval[R], fe: (Throwable) ⇒ Coeval[R]): Coeval[R]

    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.

    fa

    function that transforms a successful result of the receiver

    fe

    function that transforms an error of the receiver

  44. def value: A

    Evaluates the underlying computation and returns the result.

    Evaluates the underlying computation and returns the result.

    NOTE: this can throw exceptions.

    Alias for apply.

  45. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  46. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  47. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  48. def zip[B](that: Coeval[B]): Coeval[(A, B)]

    Zips the values of this and that coeval, and creates a new coeval that will emit the tuple of their results.

  49. def zipMap[B, C](that: Coeval[B])(f: (A, B) ⇒ C): Coeval[C]

    Zips the values of this and that and applies the given mapping function on their results.

Deprecated Value Members

  1. def dematerializeAttempt[B](implicit ev: <:<[A, Attempt[B]]): Coeval[B]

    Dematerializes the source's result from a Coeval.Attempt.

    Dematerializes the source's result from a Coeval.Attempt.

    Deprecated, please use Coeval#dematerialize or just flatMap.

    The reason for the deprecation is the naming alignment with the Cats ecosystem, where Attempt is being used as an alias for Either[Throwable, A].

    Annotations
    @deprecated
    Deprecated

    (Since version 2.3.0) Use Coeval#dematerialize or Coeval#flatMap

  2. def materializeAttempt: Coeval[Attempt[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.

    Deprecated, please use Coeval#attempt or Coeval#materialize.

    The reason for the deprecation is the naming alignment with the Cats ecosystem, where Attempt is being used as an alias for Either[Throwable, A].

    Annotations
    @deprecated
    Deprecated

    (Since version 2.3.0) Use Coeval#attempt or Coeval#materialize

Inherited from Serializable

Inherited from Serializable

Inherited from () ⇒ A

Inherited from AnyRef

Inherited from Any

Ungrouped