FuncType - v0.8.85
    Preparing search index...

    Interface Either<L, R>

    Base interface for all functype data structures. This provides a standard contract with core functional programming traits.

    // Implementing FunctypeBase for a custom data structure
    class MyContainer<T> implements FunctypeBase<T, "Empty" | "Full"> {
    // Implementation of all required methods...
    }
    interface Either<L extends Type, R extends Type> {
        _tag: "Left" | "Right";
        "[iterator]": () => Iterator<R>;
        ap: <U extends unknown>(ff: Either<L, (value: R) => U>) => Either<L, U>;
        bimap: <L2 extends unknown, R2 extends unknown>(
            fl: (value: L) => L2,
            fr: (value: R) => R2,
        ) => Either<L2, R2>;
        flatMap: <U extends unknown>(f: (value: R) => Either<L, U>) => Either<L, U>;
        flatMapAsync: <U extends unknown>(
            f: (value: R) => Promise<Either<L, U>>,
        ) => Promise<Either<L, U>>;
        fold: <T extends unknown>(
            onLeft: (value: L) => T,
            onRight: (value: R) => T,
        ) => T;
        get: () => R;
        getOrElse: (defaultValue: R) => R;
        getOrThrow: (error?: Error) => R;
        isLeft: () => boolean;
        isRight: () => boolean;
        lazyMap: <U extends unknown>(
            f: (value: R) => U,
        ) => Generator<Either<L, U>, void, unknown>;
        map: <U extends unknown>(f: (value: R) => U) => Either<L, U>;
        mapAsync: <U extends unknown>(
            f: (value: R) => Promise<U>,
        ) => Promise<Either<L, U>>;
        mapLeft: <L2 extends unknown>(f: (value: L) => L2) => Either<L2, R>;
        merge: <L1 extends unknown, R1 extends unknown>(
            other: Either<L1, R1>,
        ) => Either<L | L1, [R, R1]>;
        orNull: () => null | R;
        orUndefined: () => undefined | R;
        swap: () => Either<R, L>;
        tap: (f: (value: R) => void) => Either<L, R>;
        tapLeft: (f: (value: L) => void) => Either<L, R>;
        toList: () => List<R>;
        toOption: () => Option<R>;
        toString: () => string;
        traverse: <U extends unknown>(
            f: (value: R) => Either<L, U>,
        ) => Either<L, U[]>;
        value: L | R;
        yield: () => Generator<R, void, unknown>;
        get isEmpty(): boolean;
        get size(): number;
        contains(value: R): boolean;
        count(p: (x: R) => boolean): number;
        exists(p: (a: R) => boolean): boolean;
        find(p: (a: R) => boolean): Option<R>;
        foldLeft<B>(z: B): (op: (b: B, a: R) => B) => B;
        foldRight<B>(z: B): (op: (a: R, b: B) => B) => B;
        forEach(f: (a: R) => void): void;
        match<T>(patterns: { Left: (value: L) => T; Right: (value: R) => T }): T;
        orElse(alternative: Either<L, R>): Either<L, R>;
        pipe<U extends unknown>(f: (value: L | R) => U): U;
        pipeEither<U extends unknown>(
            onLeft: (value: L) => U,
            onRight: (value: R) => U,
        ): U;
        reduce(f: (b: R, a: R) => R): R;
        reduceRight(f: (b: R, a: R) => R): R;
        serialize(): SerializationMethods<R>;
        toJSON(): { _tag: "Left" | "Right"; value: L | R };
        toValue(): { _tag: "Left" | "Right"; value: L | R };
    }

    Type Parameters

    • L extends Type

      The type of value contained in the functor

    • R extends Type

      The type tag for pattern matching (e.g., "Some" | "None" for Option)

    Hierarchy (View Summary)

    Index

    Properties

    _tag: "Left" | "Right"
    "[iterator]": () => Iterator<R>
    ap: <U extends unknown>(ff: Either<L, (value: R) => U>) => Either<L, U>
    bimap: <L2 extends unknown, R2 extends unknown>(
        fl: (value: L) => L2,
        fr: (value: R) => R2,
    ) => Either<L2, R2>
    flatMap: <U extends unknown>(f: (value: R) => Either<L, U>) => Either<L, U>
    flatMapAsync: <U extends unknown>(
        f: (value: R) => Promise<Either<L, U>>,
    ) => Promise<Either<L, U>>
    fold: <T extends unknown>(
        onLeft: (value: L) => T,
        onRight: (value: R) => T,
    ) => T

    Pattern matches over the structure, applying specific handlers for each variant

    Type declaration

      • <T extends unknown>(onLeft: (value: L) => T, onRight: (value: R) => T): T
      • Type Parameters

        • T extends unknown

        Parameters

        • onLeft: (value: L) => T
        • onRight: (value: R) => T

        Returns T

        The result of applying the appropriate function

    get: () => R
    getOrElse: (defaultValue: R) => R
    getOrThrow: (error?: Error) => R
    isLeft: () => boolean
    isRight: () => boolean
    lazyMap: <U extends unknown>(
        f: (value: R) => U,
    ) => Generator<Either<L, U>, void, unknown>
    map: <U extends unknown>(f: (value: R) => U) => Either<L, U>
    mapAsync: <U extends unknown>(
        f: (value: R) => Promise<U>,
    ) => Promise<Either<L, U>>
    mapLeft: <L2 extends unknown>(f: (value: L) => L2) => Either<L2, R>
    merge: <L1 extends unknown, R1 extends unknown>(
        other: Either<L1, R1>,
    ) => Either<L | L1, [R, R1]>
    orNull: () => null | R
    orUndefined: () => undefined | R
    swap: () => Either<R, L>
    tap: (f: (value: R) => void) => Either<L, R>
    tapLeft: (f: (value: L) => void) => Either<L, R>
    toList: () => List<R>
    toOption: () => Option<R>
    toString: () => string

    Returns a string representation of an object.

    traverse: <U extends unknown>(f: (value: R) => Either<L, U>) => Either<L, U[]>
    value: L | R
    yield: () => Generator<R, void, unknown>

    Accessors

    • get isEmpty(): boolean

      Returns boolean

    • get size(): number

      Returns number

    Methods

    • 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: R) => 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: R) => boolean

      Returns boolean

    • 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: R) => boolean

      Returns Option<R>

    • Left-associative fold using the provided zero value and operation

      Type Parameters

      • B

      Parameters

      • z: B

        Zero/identity value

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

      A function that takes an operation to apply

    • Right-associative fold using the provided zero value and operation

      Type Parameters

      • B

      Parameters

      • z: B

        Zero/identity value

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

      A function that takes an operation to apply

    • 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: R) => void

      Returns void

    • Pattern matches over the Either, applying a handler function based on the variant

      Type Parameters

      • T

      Parameters

      • patterns: { Left: (value: L) => T; Right: (value: R) => T }

        Object with handler functions for Left and Right variants

      Returns T

      The result of applying the matching handler function

    • Pipes the Either value through the provided function

      Type Parameters

      • U extends unknown

      Parameters

      • f: (value: L | R) => U

        The function to apply to the value (Left or Right)

      Returns U

      The result of applying the function to the value

    • Pipes the value through the provided function based on whether this is a Left or Right

      Type Parameters

      • U extends unknown

      Parameters

      • onLeft: (value: L) => U

        The function to apply if this is a Left

      • onRight: (value: R) => U

        The function to apply if this is a Right

      Returns U

      The result of applying the appropriate function

    • Custom JSON serialization that excludes getter properties

      Returns { _tag: "Left" | "Right"; value: L | R }

    • Returns the value and tag for inspection

      Returns { _tag: "Left" | "Right"; value: L | R }