@telostat/prelude - v0.7.0
    Preparing search index...

    Interface EitherAsync<L, R>

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

    Type Parameters

    • L
    • R

    Hierarchy

    Index

    Properties

    then: <TResult1 = Either<L, R>, TResult2 = never>(
        onfulfilled?:
            | ((value: Either) => TResult1 | PromiseLike<TResult1>)
            | null,
        onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null,
    ) => PromiseLike<TResult1 | TResult2>

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

    Type Declaration

      • <TResult1 = Either<L, R>, TResult2 = never>(
            onfulfilled?:
                | ((value: Either) => TResult1 | PromiseLike<TResult1>)
                | null,
            onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null,
        ): PromiseLike<TResult1 | TResult2>
      • Attaches callbacks for the resolution and/or rejection of the Promise.

        Type Parameters

        Parameters

        • Optionalonfulfilled: ((value: Either) => TResult1 | PromiseLike<TResult1>) | null

          The callback to execute when the Promise is resolved.

        • Optionalonrejected: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null

          The callback to execute when the Promise is rejected.

        Returns PromiseLike<TResult1 | TResult2>

        A Promise for the completion of which ever callback is executed.

    Methods

    • Returns the first Right between the future value of this and another EitherAsync or the Left in the argument if both this and the argument resolve to Left

      Parameters

      Returns EitherAsync<L, R>

    • Applies a Right function wrapped in EitherAsync over a future Right value. Returns Left if either the this resolves to a Left or the function is Left

      Type Parameters

      • L2
      • R2

      Parameters

      Returns EitherAsync<L | L2, Awaited<R2>>

    • 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 EitherAsync<Awaited<L2>, Awaited<R2>>

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

      Type Parameters

      • T

      Parameters

      Returns Promise<T>

    • Transforms this with a function that returns a EitherAsync. Behaviour is the same as the regular Either#chain

      Type Parameters

      • L2
      • R2

      Parameters

      Returns EitherAsync<L | L2, R2>

    • The same as EitherAsync#chain but executes the transformation function only if the value is Left. Useful for recovering from errors

      Type Parameters

      • L2
      • R2

      Parameters

      Returns EitherAsync<L2, R | R2>

    • Returns this if it resolves to a Left, otherwise it returns the result of applying the function argument to this and wrapping it in a Right

      Type Parameters

      • R2

      Parameters

      Returns EitherAsync<L, Awaited<R2>>

    • Parameters

      • effect: () => any

      Returns EitherAsync<L, R>

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

      Parameters

      • effect: (value: L) => any

      Returns EitherAsync<L, R>

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

      Parameters

      • effect: (value: R) => any

      Returns 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 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 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<Either<L, R>>

    • Returns Right if this is Left and vice versa

      Returns EitherAsync<R, L>

    • Converts this to a MaybeAsync, discarding any error values

      Returns MaybeAsync<R>

    • Useful if you are not interested in the result of an operation

      Returns EitherAsync<L, void>