Interface EitherAsync<L, R>

interface EitherAsync<L, R> {
    then: <TResult1 = functional.Either<L, R>, TResult2 = never>(
        onfulfilled?:
            | null
            | (value: functional.Either<L, R>) => TResult1 | PromiseLike<TResult1>,
        onrejected?: null | (reason: any) => TResult2 | PromiseLike<TResult2>,
    ) => PromiseLike<TResult1 | TResult2>;
    alt(other: functional.EitherAsync<L, R>): functional.EitherAsync<L, R>;
    ap<L2, R2>(
        other: PromiseLike<functional.Either<L2, (value: R) => R2>>,
    ): functional.EitherAsync<L | L2, Awaited<R2>>;
    bimap<L2, R2>(
        f: (value: L) => L2,
        g: (value: R) => R2,
    ): functional.EitherAsync<Awaited<L2>, Awaited<R2>>;
    caseOf<T>(patterns: functional.EitherPatterns<L, R, T>): Promise<T>;
    chain<L2, R2>(
        f: (value: R) => PromiseLike<functional.Either<L2, R2>>,
    ): functional.EitherAsync<L | L2, R2>;
    chainLeft<L2, R2>(
        f: (value: L) => PromiseLike<functional.Either<L2, R2>>,
    ): functional.EitherAsync<L2, R | R2>;
    extend<R2>(
        f: (value: functional.EitherAsync<L, R>) => R2,
    ): functional.EitherAsync<L, Awaited<R2>>;
    "fantasy-land/alt"(
        other: functional.EitherAsync<L, R>,
    ): functional.EitherAsync<L, R>;
    "fantasy-land/chain"<R2>(
        f: (value: R) => PromiseLike<functional.Either<L, R2>>,
    ): functional.EitherAsync<L, R2>;
    finally(effect: () => any): functional.EitherAsync<L, R>;
    ifLeft(effect: (value: L) => any): functional.EitherAsync<L, R>;
    ifRight(effect: (value: R) => any): functional.EitherAsync<L, R>;
    join<L2, R2>(
        this: functional.EitherAsync<L, functional.Either<L2, R2>>,
    ): functional.EitherAsync<L | L2, R2>;
    leftOrDefault(defaultValue: L): Promise<L>;
    map<R2>(f: (value: R) => R2): functional.EitherAsync<L, Awaited<R2>>;
    mapLeft<L2>(f: (value: L) => L2): functional.EitherAsync<Awaited<L2>, R>;
    orDefault(defaultValue: R): Promise<R>;
    run(): Promise<functional.Either<L, R>>;
    swap(): functional.EitherAsync<R, L>;
    toMaybeAsync(): functional.MaybeAsync<R>;
    void(): functional.EitherAsync<L, void>;
}

Type Parameters

  • L
  • R

Hierarchy

Properties

then: <TResult1 = functional.Either<L, R>, TResult2 = never>(
    onfulfilled?:
        | null
        | (value: functional.Either<L, R>) => 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

  • Given two functions, maps the value that the Promise inside this resolves to using the first if it is Left or using the second one if it is Right

    Type Parameters

    • L2
    • R2

    Parameters

    • f: (value: L) => L2
    • g: (value: R) => R2

    Returns functional.EitherAsync<Awaited<L2>, Awaited<R2>>

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

    Parameters

    • effect: (value: L) => any

    Returns functional.EitherAsync<L, R>

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

    Parameters

    • effect: (value: R) => any

    Returns functional.EitherAsync<L, R>

  • Returns a Promise that resolves to the value inside this if it's Left or a default value if this is Right

    Parameters

    • defaultValue: L

    Returns Promise<L>

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

    Type Parameters

    • R2

    Parameters

    • f: (value: R) => R2

    Returns functional.EitherAsync<L, Awaited<R2>>

  • Maps the Left value of this, acts like an identity if this is Right

    Type Parameters

    • L2

    Parameters

    • f: (value: L) => L2

    Returns functional.EitherAsync<Awaited<L2>, R>

  • Returns a Promise that resolves to the value inside this if it's Right or a default value if this is Left

    Parameters

    • defaultValue: R

    Returns Promise<R>

  • 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 EitherAsync resolved to a Left, run will return a Promise resolved to that Left. If any of the promises were to be rejected then run will return a Promise resolved to a Left with the rejection value inside If an exception is thrown then run will return a Promise resolved to a Left with the exception inside If none of the above happen then a promise resolved to the returned value wrapped in a Right will be returned

    Returns Promise<functional.Either<L, R>>