interface MaybeAsync<T> {
    then: <TResult1 = functional.Maybe<T>, TResult2 = never>(
        onfulfilled?:
            | null
            | (value: functional.Maybe<T>) => TResult1 | PromiseLike<TResult1>,
        onrejected?: null | (reason: any) => TResult2 | PromiseLike<TResult2>,
    ) => PromiseLike<TResult1 | TResult2>;
    alt(other: functional.MaybeAsync<T>): functional.MaybeAsync<T>;
    ap<U>(
        maybeF: PromiseLike<functional.Maybe<(value: T) => U>>,
    ): functional.MaybeAsync<Awaited<U>>;
    caseOf<U>(patterns: functional.MaybePatterns<T, U>): Promise<U>;
    chain<U>(
        f: (value: T) => PromiseLike<functional.Maybe<U>>,
    ): functional.MaybeAsync<U>;
    extend<U>(
        f: (value: functional.MaybeAsync<T>) => U,
    ): functional.MaybeAsync<Awaited<U>>;
    "fantasy-land/alt"(
        other: functional.MaybeAsync<T>,
    ): functional.MaybeAsync<T>;
    "fantasy-land/chain"<U>(
        f: (value: T) => PromiseLike<functional.Maybe<U>>,
    ): functional.MaybeAsync<U>;
    "fantasy-land/filter"<U>(
        pred: (value: T) => value is U,
    ): functional.MaybeAsync<U>;
    "fantasy-land/filter"(
        pred: (value: T) => boolean,
    ): functional.MaybeAsync<T>;
    filter<U>(pred: (value: T) => value is U): functional.MaybeAsync<U>;
    filter(pred: (value: T) => boolean): functional.MaybeAsync<T>;
    finally(effect: () => any): functional.MaybeAsync<T>;
    ifJust(effect: (value: T) => any): functional.MaybeAsync<T>;
    ifNothing(effect: () => any): functional.MaybeAsync<T>;
    join<U>(
        this: functional.MaybeAsync<functional.Maybe<U>>,
    ): functional.MaybeAsync<U>;
    map<U>(f: (value: T) => U): functional.MaybeAsync<Awaited<U>>;
    orDefault(defaultValue: T): Promise<T>;
    run(): Promise<functional.Maybe<T>>;
    toEitherAsync<L>(error: L): functional.EitherAsync<L, T>;
    void(): functional.MaybeAsync<void>;
}

Type Parameters

  • T

Hierarchy

Properties

then: <TResult1 = functional.Maybe<T>, TResult2 = never>(
    onfulfilled?:
        | null
        | (value: functional.Maybe<T>) => TResult1 | PromiseLike<TResult1>,
    onrejected?: null | (reason: any) => TResult2 | PromiseLike<TResult2>,
) => PromiseLike<TResult1 | TResult2>

WARNING: This is implemented only for Promise compatibility. Please use chain instead.

Type declaration

Methods

  • Structural pattern matching for MaybeAsync in the form of a function

    Type Parameters

    • U

    Parameters

    Returns Promise<U>

  • Takes a predicate function and returns this if the predicate, applied to the resolved value, is true or Nothing if it's false

    Type Parameters

    • U

    Parameters

    • pred: (value: T) => value is U

    Returns functional.MaybeAsync<U>

  • Takes a predicate function and returns this if the predicate, applied to the resolved value, is true or Nothing if it's false

    Parameters

    • pred: (value: T) => boolean

    Returns functional.MaybeAsync<T>

  • Runs an effect if this is Just, returns this to make chaining other methods possible

    Parameters

    • effect: (value: T) => any

    Returns functional.MaybeAsync<T>

  • Runs an effect if this is Nothing, returns this to make chaining other methods possible

    Parameters

    • effect: () => any

    Returns functional.MaybeAsync<T>

  • Transforms the value inside this with a given function. If the MaybeAsync that is being mapped resolves to Nothing then the mapping function won't be called and run will resolve the whole thing to Nothing, just like the regular Maybe#map

    Type Parameters

    • U

    Parameters

    • f: (value: T) => U

    Returns functional.MaybeAsync<Awaited<U>>

  • Returns the default value if this is Nothing, otherwise it returns a Promise that will resolve to the value inside this

    Parameters

    • defaultValue: T

    Returns Promise<T>

  • It's important to remember how run will behave because in an async context there are other ways for a function to fail other than to return a Nothing, for example: If any of the computations inside MaybeAsync resolved to Nothing, run will return a Promise resolved to Nothing. If any of the promises were to be rejected then run will return a Promise resolved to Nothing. If an exception is thrown then run will return a Promise resolved to Nothing. If none of the above happen then a promise resolved to the returned value wrapped in a Just will be returned.

    Returns Promise<functional.Maybe<T>>