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

    Interface MaybeAsync<T>

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

    Type Parameters

    • T

    Hierarchy

    • PromiseLike<Maybe<T>>
      • MaybeAsync
    Index

    Properties

    then: <TResult1 = Maybe<T>, TResult2 = never>(
        onfulfilled?:
            | ((value: Maybe) => 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 = Maybe<T>, TResult2 = never>(
            onfulfilled?:
                | ((value: Maybe) => 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

        • TResult1 = Maybe<T>
        • TResult2 = never

        Parameters

        • Optionalonfulfilled: ((value: Maybe) => 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 Just between the future value of this and another future Maybe or future Nothing if both this and the argument are Nothing

      Parameters

      Returns MaybeAsync<T>

    • Maps the future value of this with another future Maybe function

      Type Parameters

      • U

      Parameters

      • maybeF: PromiseLike<Maybe<(value: T) => U>>

      Returns MaybeAsync<Awaited<U>>

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

      Type Parameters

      • U

      Parameters

      Returns Promise<U>

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

      Type Parameters

      • U

      Parameters

      • f: (value: T) => PromiseLike<Maybe<U>>

      Returns MaybeAsync<U>

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

      Type Parameters

      • U

      Parameters

      Returns MaybeAsync<Awaited<U>>

    • Type Parameters

      • U

      Parameters

      • f: (value: T) => PromiseLike<Maybe<U>>

      Returns MaybeAsync<U>

    • Type Parameters

      • U

      Parameters

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

      Returns MaybeAsync<U>

    • Parameters

      • pred: (value: T) => boolean

      Returns MaybeAsync<T>

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

    • Parameters

      • effect: () => any

      Returns MaybeAsync<T>

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

      Parameters

      • effect: (value: T) => any

      Returns MaybeAsync<T>

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

      Parameters

      • effect: () => any

      Returns 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 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<Maybe<T>>

    • Converts this to a EitherAsync with a default error value

      Type Parameters

      • L

      Parameters

      • error: L

      Returns EitherAsync<L, T>

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

      Returns MaybeAsync<void>