FuncType - v0.16.0
    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<T> {
        _meta: TaskMetadata;
        _tag: "Ok" | "Err";
        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;
        recover: (value: T) => Ok<T>;
        recoverWith: (f: (error: Throwable) => T) => Ok<T>;
        toEither: () => Either<Throwable, T>;
        toList: () => List<T>;
        toOption: () => Option<T>;
        toTry: () => Try<T>;
        value?: T;
        get isEmpty(): boolean;
        get size(): number;
        contains(value: T): 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;
        getOrElse(defaultValue: T): T;
        getOrThrow(error?: Error): T;
        orElse(alternative: Extractable<T>): Extractable<T>;
        orNull(): T | null;
        orUndefined(): T | undefined;
        reduce(f: (b: T, a: T) => T): T;
        reduceRight(f: (b: T, a: T) => T): T;
        serialize(): SerializationMethods<T>;
        toPromise(): Promise<T>;
    }

    Type Parameters

    • T

      The type of value contained in the functor

    Hierarchy (View Summary)

    Index

    Properties

    _tag: "Ok" | "Err"
    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

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

    Type Declaration

      • <U>(onErr: (error: Throwable) => U, onOk: (value: T) => U): U
      • Type Parameters

        • U

        Parameters

        • onErr: (error: Throwable) => U
        • onOk: (value: T) => U

        Returns U

        The result of applying the appropriate function

    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
    recover: (value: T) => Ok<T>
    recoverWith: (f: (error: Throwable) => T) => Ok<T>
    toEither: () => Either<Throwable, T>
    toList: () => List<T>
    toOption: () => Option<T>
    toTry: () => Try<T>
    value?: T

    Accessors

    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: 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 the contained value or a default value

      Parameters

      • defaultValue: T

        The value to return if extraction fails

      Returns T

      The contained value or defaultValue

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

      Returns T | null

      The contained value or null

    • Returns the contained value or undefined

      Returns T | undefined

      The contained value or undefined

    • 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