FuncType - v0.8.85
    Preparing search index...

    Interface LazyType<T>

    The Lazy type represents a computation that is deferred until needed. It provides memoization and safe evaluation with integration to Option, Either, and Try.

    interface LazyType<T extends Type> {
        _tag: "Lazy";
        foldLeft: <B>(z: B) => (op: (b: B, a: T) => B) => B;
        foldRight: <B>(z: B) => (op: (a: T, b: B) => B) => B;
        isEvaluated: boolean;
        get isEmpty(): boolean;
        get size(): number;
        ap<U extends unknown>(ff: LazyType<(value: T) => U>): LazyType<U>;
        contains(value: T): boolean;
        count(p: (x: T) => boolean): number;
        exists(p: (a: T) => boolean): boolean;
        filter(predicate: (value: T) => boolean): LazyType<Option<T>>;
        find(p: (a: T) => boolean): Option<T>;
        flatMap<U extends unknown>(f: (value: T) => LazyType<U>): LazyType<U>;
        flatMapAsync<U extends unknown>(
            f: (value: T) => Promise<LazyType<U>>,
        ): Promise<LazyType<U>>;
        fold<U>(f: (value: T) => U): U;
        foldWith<U>(
            onFailure: (error: unknown) => U,
            onSuccess: (value: T) => U,
        ): U;
        forEach(f: (a: T) => void): void;
        get(): T;
        getOrElse(defaultValue: T): T;
        getOrNull(): null | T;
        getOrThrow(error: Error): T;
        map<U extends unknown>(f: (value: T) => U): LazyType<U>;
        mapAsync<U extends unknown>(
            f: (value: T) => Promise<U>,
        ): Promise<LazyType<U>>;
        match<R>(patterns: { Lazy: (value: T) => R }): R;
        orElse(alternative: Extractable<T>): Extractable<T>;
        orNull(): null | T;
        orUndefined(): undefined | T;
        pipe<U extends unknown>(f: (value: T) => U): U;
        recover(f: (error: unknown) => T): LazyType<T>;
        recoverWith(f: (error: unknown) => LazyType<T>): LazyType<T>;
        reduce(f: (b: T, a: T) => T): T;
        reduceRight(f: (b: T, a: T) => T): T;
        serialize(): SerializationMethods<T>;
        tap(f: (value: T) => void): LazyType<T>;
        tapError(f: (error: unknown) => void): LazyType<T>;
        toEither(): Either<unknown, T>;
        toEitherWith<E>(mapError: (error: unknown) => E): Either<E, T>;
        toOption(): Option<T>;
        toString(): string;
        toTry(): Try<T>;
        toValue(): { _tag: "Lazy"; evaluated: boolean; value?: T };
    }

    Type Parameters

    • T extends Type

      The type of the value to be computed

    Hierarchy (View Summary)

    Index

    Properties

    _tag: "Lazy"

    Tag identifying this as a Lazy type

    foldLeft: <B>(z: B) => (op: (b: B, a: T) => B) => B

    Left fold operation

    Type declaration

      • <B>(z: B): (op: (b: B, a: T) => B) => B
      • Type Parameters

        • B

        Parameters

        • z: B

          Initial value

        Returns (op: (b: B, a: T) => B) => B

        Function that takes an operator and applies it

    foldRight: <B>(z: B) => (op: (a: T, b: B) => B) => B

    Right fold operation

    Type declaration

      • <B>(z: B): (op: (a: T, b: B) => B) => B
      • Type Parameters

        • B

        Parameters

        • z: B

          Initial value

        Returns (op: (a: T, b: B) => B) => B

        Function that takes an operator and applies it

    isEvaluated: boolean

    Whether the computation has been evaluated

    Accessors

    • get isEmpty(): boolean

      Returns boolean

    • get size(): number

      Returns number

    Methods

    • Applies a wrapped function to a wrapped value (Applicative pattern)

      Type Parameters

      • U extends unknown

      Parameters

      • ff: LazyType<(value: T) => U>

        A Lazy containing a function from T to U

      Returns LazyType<U>

      A new Lazy containing the result

    • Counts elements that satisfy the predicate. For single-value containers: returns 0 or 1 For collections: returns the count of matching elements

      Parameters

      • p: (x: T) => boolean

      Returns number

    • Tests whether any element satisfies the predicate. For single-value containers: tests the single value For collections: returns true if any element matches

      Parameters

      • p: (a: T) => boolean

      Returns boolean

    • Returns a Lazy that filters the value based on a predicate

      Parameters

      • predicate: (value: T) => boolean

        The predicate function

      Returns LazyType<Option<T>>

      A Lazy containing an Option of the value

    • Finds the first element that satisfies the predicate. For single-value containers: returns Some(value) if predicate matches, None otherwise For collections: returns the first matching element wrapped in Option

      Parameters

      • p: (a: T) => boolean

      Returns Option<T>

    • Maps the value using a function that returns a Lazy

      Type Parameters

      • U extends unknown

      Parameters

      • f: (value: T) => LazyType<U>

        The mapping function returning a Lazy

      Returns LazyType<U>

      A new Lazy containing the flattened result

    • Maps the value using an async function that returns a Lazy

      Type Parameters

      • U extends unknown

      Parameters

      • f: (value: T) => Promise<LazyType<U>>

        The async mapping function returning a Lazy

      Returns Promise<LazyType<U>>

      A Promise of a new Lazy containing the flattened result

    • Pattern matching on the Lazy value

      Type Parameters

      • U

      Parameters

      • f: (value: T) => U

        Function to apply to the computed value

      Returns U

      The result of applying f to the computed value

    • Pattern matching with success and failure handlers

      Type Parameters

      • U

      Parameters

      • onFailure: (error: unknown) => U

        Function to handle computation failure

      • onSuccess: (value: T) => U

        Function to handle successful computation

      Returns U

      The result of the appropriate handler

    • Applies an effect function to each element. For single-value containers: applies to the value if present For collections: applies to each element

      Parameters

      • f: (a: T) => void

      Returns void

    • Forces evaluation of the lazy value and returns the result. The result is memoized after first evaluation.

      Returns T

      The computed value

      Any error thrown by the computation

    • Returns the computed value or a default value if computation fails

      Parameters

      • defaultValue: T

        The value to return if computation fails

      Returns T

      The computed value or defaultValue

    • Returns the computed value or null if computation fails

      Returns null | T

      The computed value or null

    • Returns the computed value or throws a specified error if computation fails

      Parameters

      • error: Error

        The error to throw if computation fails

      Returns T

      The computed value

      The specified error if computation fails

    • Maps the value inside the Lazy using the provided function

      Type Parameters

      • U extends unknown

      Parameters

      • f: (value: T) => U

        The mapping function

      Returns LazyType<U>

      A new Lazy containing the mapped value

    • Maps the value inside the Lazy using an async function

      Type Parameters

      • U extends unknown

      Parameters

      • f: (value: T) => Promise<U>

        The async mapping function

      Returns Promise<LazyType<U>>

      A Promise of a new Lazy containing the mapped value

    • Pattern matching for the Lazy type

      Type Parameters

      • R

      Parameters

      • patterns: { Lazy: (value: T) => R }

        Object with handler for Lazy pattern

      Returns R

      The result of the matched handler

    • Returns this container if it has a value, otherwise returns the alternative

      Parameters

      • alternative: Extractable<T>

        The alternative container

      Returns Extractable<T>

      This container or the alternative

    • Returns the contained value or null

      Returns null | T

      The contained value or null

    • Returns the contained value or undefined

      Returns undefined | T

      The contained value or undefined

    • Pipes the value through the provided function

      Type Parameters

      • U extends unknown

        The return type of the function

      Parameters

      • f: (value: T) => U

        The function to apply to the value

      Returns U

      The result of applying the function to the value

    • Recovers from a failed computation by providing an alternative value

      Parameters

      • f: (error: unknown) => T

        Function that takes the error and returns a recovery value

      Returns LazyType<T>

      A new Lazy that will use the recovery function if computation fails

    • Recovers from a failed computation by providing an alternative Lazy

      Parameters

      • f: (error: unknown) => LazyType<T>

        Function that takes the error and returns a recovery Lazy

      Returns LazyType<T>

      A new Lazy that will use the recovery Lazy if computation fails

    • Applies an effect function to the value if computation succeeds

      Parameters

      • f: (value: T) => void

        The effect function

      Returns LazyType<T>

      This Lazy for chaining

    • Applies an effect function to the error if computation fails

      Parameters

      • f: (error: unknown) => void

        The effect function for errors

      Returns LazyType<T>

      This Lazy for chaining

    • Evaluates the computation and returns it as an Either

      Returns Either<unknown, T>

      Right containing the value if successful, Left containing the error if computation fails

    • Evaluates the computation and returns it as an Either with a mapped error

      Type Parameters

      • E

      Parameters

      • mapError: (error: unknown) => E

        Function to map the error

      Returns Either<E, T>

      Right containing the value if successful, Left containing the mapped error if computation fails

    • Evaluates the computation and returns it as an Option

      Returns Option<T>

      Some containing the value if successful, None if computation fails

    • Creates a string representation of the Lazy

      Returns string

      String representation showing evaluation status

    • Evaluates the computation and returns it as a Try

      Returns Try<T>

      Try containing the result of the computation

    • Converts the Lazy to a value object

      Returns { _tag: "Lazy"; evaluated: boolean; value?: T }

      Object representation of the Lazy with evaluation state