sealed abstract class Eval[+A] extends Serializable
Eval is a monad which controls evaluation.
This type wraps a value (or a computation that produces a value)
and can produce it on command via the .value
method.
There are three basic evaluation strategies:
- Now: evaluated immediately
- Later: evaluated once when value is needed
- Always: evaluated every time value is needed
The Later and Always are both lazy strategies while Now is eager. Later and Always are distinguished from each other only by memoization: once evaluated Later will save the value to be returned immediately if it is needed again. Always will run its computation every time.
Eval 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.
It is not generally good style to pattern-match on Eval instances. Rather, use .map and .flatMap to chain computation, and use .value to get the result when needed. It is also not good style to create Eval instances whose computation involves calling .value on another Eval instance -- this can defeat the trampolining and lead to stack overflows.
- Self Type
- Eval[A]
- Source
- Eval.scala
- Alphabetic
- By Inheritance
- Eval
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- abstract def memoize: Eval[A]
Ensure that the result of the computation (if any) will be memoized.
Ensure that the result of the computation (if any) will be memoized.
Practically, this means that when called on an Always[A] a Later[A] with an equivalent computation will be returned.
- abstract def value: A
Evaluate the computation and return an A value.
Evaluate the computation and return an A value.
For lazy instances (Later, Always), any necessary computation will be performed at this point. For eager instances (Now), a value will be immediately returned.
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
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- def flatMap[B](f: (A) => Eval[B]): Eval[B]
Lazily perform a computation based on an Eval[A], using the function
f
to produce an Eval[B] given an A.Lazily perform a computation based on an Eval[A], using the function
f
to produce an Eval[B] given an A.This call is stack-safe -- many .flatMap calls may be chained without consumed additional stack during evaluation. It is also written to avoid left-association problems, so that repeated calls to .flatMap will be efficiently applied.
Computation performed in f is always lazy, even when called on an eager (Now) instance.
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def map[B](f: (A) => B): Eval[B]
Transform an Eval[A] into an Eval[B] given the transformation function
f
.Transform an Eval[A] into an Eval[B] given the transformation function
f
.This call is stack-safe -- many .map calls may be chained without consumed additional stack during evaluation.
Computation performed in f is always lazy, even when called on an eager (Now) instance.
- 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 synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()