Eval

public class Eval<A> : EvalOf<A>

Eval is a data type that describes a potentially lazy computation that produces a value.

Eval has three different evaluation strategies: - Now: the computation is evaluated immediately. - Later: the computation is evaluated when it is needed (typically by calling Eval.value()), just once. This value is cached, so subsequent invocations do not trigger additional computations of the value. - Always: the computation is evaluated every time it is needed (typically by calling Eval.value()).

Now is an eager evaluation strategy, whereas Later and Always are lazy.

  • Creates an Eval value with a value that is immediately evaluated.

    Declaration

    Swift

    public static func now(_ a: A) -> Eval<A>

    Parameters

    a

    Value to be wrapped in the Eval.

    Return Value

    An Eval value.

  • Creates an Eval value that will be evaluated using the Later evaluation strategy.

    Declaration

    Swift

    public static func later(_ f: @escaping () -> A) -> Eval<A>

    Parameters

    f

    Function producing the value to be wrapped in an Eval.

    Return Value

    An Eval value.

  • Creates an Eval value that will be evaluated using the Always evaluation strategy.

    Declaration

    Swift

    public static func always(_ f: @escaping () -> A) -> Eval<A>

    Parameters

    f

    Function producing the value to be wrapped in an Eval.

    Return Value

    An Eval value.

  • Creates an Eval value that defers a computation that produces another Eval.

    Declaration

    Swift

    public static func `defer`(_ f: @escaping () -> Eval<A>) -> Eval<A>

    Parameters

    f

    Function producing an Eval.

    Return Value

    An Eval value.

  • Safe downcast.

    Declaration

    Swift

    public static func fix(_ fa: EvalOf<A>) -> Eval<A>

    Parameters

    fa

    Value in the higher-kind form.

    Return Value

    Value cast to Eval.

  • Computes the value wrapped in this Eval.

    Declaration

    Swift

    public func value() -> A

    Return Value

    Value wrapped in this Eval.

  • Provides an Eval that memoizes the result of its enclosed computation.

    Declaration

    Swift

    public func memoize() -> Eval<A>

    Return Value

    An Eval value.

  • Provides a unit in an Eval.

    Declaration

    Swift

    static var unit: Eval<Void> { get }
  • Provides a true value in an Eval.

    Declaration

    Swift

    static var `true`: Eval<Bool> { get }
  • Provides a false value in an Eval.

    Declaration

    Swift

    static var `false`: Eval<Bool> { get }
  • Provides a zero value in an Eval.

    Declaration

    Swift

    static var zero: Eval<Int> { get }
  • Provides a one value in an Eval.

    Declaration

    Swift

    static var one: Eval<Int> { get }