FuncType - v0.60.3
    Preparing search index...

    Interface TaskOutcome<T>

    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 TaskOutcome<out T> {
        _meta: TaskMetadata;
        _tag: "Ok" | "Err";
        "[toStringTag]": string;
        ap: <U>(ff: TaskOutcome<(value: T) => U>) => TaskOutcome<U>;
        error?: Throwable;
        flatMap: <U>(
            f: (value: T) => TaskOutcome<U> | Either<Throwable, U>,
        ) => TaskOutcome<U>;
        flatMapAsync: <U>(
            f: (value: T) => Promise<TaskOutcome<U>>,
        ) => Promise<TaskOutcome<U>>;
        fold: <U>(onErr: (error: Throwable) => U, onOk: (value: T) => U) => U;
        isErr: () => this is Err<T>;
        isFailure: () => this is Err<T>;
        isOk: () => this is Ok<T>;
        isSuccess: () => this is Ok<T>;
        map: <U>(f: (value: T) => U) => TaskOutcome<U>;
        mapAsync: <U>(f: (value: T) => Promise<U>) => Promise<TaskOutcome<U>>;
        mapError: (f: (error: Throwable) => Throwable) => TaskOutcome<T>;
        match: <U>(
            patterns: { Err: (error: Throwable) => U; Ok: (value: T) => U },
        ) => U;
        toEither: () => Either<Throwable, T>;
        toList: () => List<T>;
        toOption: () => Option<T>;
        toTry: () => Try<T>;
        value?: T;
        get isEmpty(): boolean;
        get size(): number;
        contains(value: unknown): boolean;
        count(p: (x: T) => boolean): number;
        doUnwrap(): DoResult<T>;
        exists(p: (a: T) => boolean): boolean;
        find(p: (a: T) => boolean): Option<T>;
        foldLeft<B>(z: B): (op: (b: B, a: T) => B) => B;
        foldRight<B>(z: B): (op: (a: T, b: B) => B) => B;
        forEach(f: (a: T) => void): void;
        or<T2 extends unknown>(alternative: Extractable<T2>): Extractable<T | T2>;
        orElse<T2 extends unknown>(defaultValue: T2): T | T2;
        orNull(): T | null;
        orThrow(error?: Error): T;
        orUndefined(): T | undefined;
        recover<U extends unknown>(value: U): Ok<T | U>;
        recoverWith<U extends unknown>(f: (error: Throwable) => U): Ok<T | U>;
        reduce<B = T>(
            op: (b: Widen<T, B>, a: Widen<T, B>) => Widen<T, B>,
        ): Widen<T, B>;
        reduceRight<B = T>(
            op: (b: Widen<T, B>, a: Widen<T, B>) => Widen<T, B>,
        ): Widen<T, B>;
        serialize(): SerializationMethods<T>;
        toPromise(): Promise<T>;
    }

    Type Parameters

    • out T

      The type of value contained in the functor

    Hierarchy (View Summary)

    Index

    Properties

    _tag: "Ok" | "Err"
    "[toStringTag]": string
    ap: <U>(ff: TaskOutcome<(value: T) => U>) => TaskOutcome<U>
    error?: Throwable
    flatMap: <U>(
        f: (value: T) => TaskOutcome<U> | Either<Throwable, U>,
    ) => TaskOutcome<U>
    flatMapAsync: <U>(
        f: (value: T) => Promise<TaskOutcome<U>>,
    ) => Promise<TaskOutcome<U>>
    fold: <U>(onErr: (error: Throwable) => U, onOk: (value: T) => U) => U
    isErr: () => this is Err<T>
    isFailure: () => this is Err<T>
    isOk: () => this is Ok<T>
    isSuccess: () => this is Ok<T>
    map: <U>(f: (value: T) => U) => TaskOutcome<U>
    mapAsync: <U>(f: (value: T) => Promise<U>) => Promise<TaskOutcome<U>>
    mapError: (f: (error: Throwable) => Throwable) => TaskOutcome<T>
    match: <U>(patterns: { Err: (error: Throwable) => U; Ok: (value: T) => U }) => U
    toEither: () => Either<Throwable, T>
    toList: () => List<T>
    toOption: () => Option<T>
    toTry: () => Try<T>
    value?: T

    Accessors

    Methods

    • Parameters

      • value: unknown

      Returns boolean

    • 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

    • 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>

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

      Type Parameters

      • B

      Parameters

      • z: B

        Zero/identity value

      Returns (op: (b: B, a: T) => 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: T, 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: T) => void

      Returns void

    • Returns this container if it has a value, otherwise returns the alternative container. The alternative may carry a different type; the result widens to Extractable<T | T2>.

      Type Parameters

      • T2 extends unknown

      Parameters

      Returns Extractable<T | T2>

      This container or the alternative

    • Returns the contained value or a default value. The default may be of a different type; the result widens to T | T2.

      Type Parameters

      • T2 extends unknown

      Parameters

      • defaultValue: T2

        The value to return if extraction fails

      Returns T | T2

      The contained value or defaultValue

    • Returns the contained value or null

      Returns T | null

      The contained value or null

    • Extract the value or throw an error

      Parameters

      • Optionalerror: Error

        Optional custom error to throw. If not provided, uses type-appropriate default error

      Returns T

      The contained value

      The specified error, container's error, or a sensible default

    • Returns the contained value or undefined

      Returns T | undefined

      The contained value or undefined

    • Type Parameters

      • U extends unknown

      Parameters

      • value: U

      Returns Ok<T | U>

    • Type Parameters

      • U extends unknown

      Parameters

      Returns Ok<T | U>

    • Converts this container to a Promise

      The behavior depends on the implementing container:

      • Success/Right/Some containers resolve with their value
      • Failure/Left/None containers reject with their error/default error

      Returns Promise<T>

      A Promise that resolves or rejects based on the container's state