Package

sbt

util

Permalink

package util

Visibility
  1. Public
  2. All

Type Members

  1. final class Always[A] extends Eval[A]

    Permalink

    Construct a lazy Eval[A] instance.

    Construct a lazy Eval[A] instance.

    This type can be used for "lazy" values. In some sense it is equivalent to using a Function0 value.

    This type will evaluate the computation every time the value is required. It should be avoided except when laziness is required and caching must be avoided. Generally, prefer Later.

  2. sealed abstract class Eval[+A] extends Serializable

    Permalink

    Eval is a monad which controls evaluation.

    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.

  3. final class Later[A] extends Eval[A]

    Permalink

    Construct a lazy Eval[A] instance.

    Construct a lazy Eval[A] instance.

    This type should be used for most "lazy" values. In some sense it is equivalent to using a lazy val.

    When caching is not required or desired (e.g. if the value produced may be large) prefer Always. When there is no computation necessary, prefer Now.

    Once Later has been evaluated, the closure (and any values captured by the closure) will not be retained, and will be available for garbage collection.

  4. final case class Now[A](value: A) extends Eval[A] with Product with Serializable

    Permalink

    Construct an eager Eval[A] instance.

    Construct an eager Eval[A] instance.

    In some sense it is equivalent to using a val.

    This type should be used when an A value is already in hand, or when the computation to produce an A value is pure and very fast.

Value Members

  1. object Always extends Serializable

    Permalink
  2. object Eval extends Serializable

    Permalink
  3. object Later extends Serializable

    Permalink

Ungrouped