easy-monad
    Preparing search index...

    Type Alias MaybeAsync<T>

    MaybeAsync: {
        doIfNoValue: (fn: () => void) => MaybeAsync<T>;
        doIfNoValueAsync: (fn: () => Promise<void>) => MaybeAsync<T>;
        doIfValue: (fn: (x: T) => void) => MaybeAsync<T>;
        doIfValueAsync: (fn: (x: T) => Promise<void>) => MaybeAsync<T>;
        getOrElse: <A>(x: A) => Promise<T | A>;
        hasValue: Promise<boolean>;
        mapValue: <A>(fn: (x: T) => A | Maybe<A>) => MaybeAsync<A>;
        mapValueAsync: <A>(fn: (x: T) => Promise<A>) => MaybeAsync<A>;
        toPromise: () => Promise<Maybe<T>>;
    } & { [key: symbol]: true }

    An async version of the Maybe monad. Basically a maybe monad, but handle async value and operations

    Type Parameters

    • T

    Type declaration

    • doIfNoValue: (fn: () => void) => MaybeAsync<T>

      Execute a function, only if a value is NOT present.

    • doIfNoValueAsync: (fn: () => Promise<void>) => MaybeAsync<T>

      Execute an asynchrone function, only if a value is NOT present.

    • doIfValue: (fn: (x: T) => void) => MaybeAsync<T>

      Execute a function only if a value is present. Will not update the value. If you want to update the value use mapValue instead.

    • doIfValueAsync: (fn: (x: T) => Promise<void>) => MaybeAsync<T>

      Execute an asynchrone function, only if a value is present. Will not update the value. If you want to update the value use mapValueAsync instead.

    • getOrElse: <A>(x: A) => Promise<T | A>

      Get the value if any. Else return a default value.

    • hasValue: Promise<boolean>

      Whether Maybe has a value or not

    • mapValue: <A>(fn: (x: T) => A | Maybe<A>) => MaybeAsync<A>

      Transform the value, if any. If the result of the maping is another Maybe, it will be flatten automatically

    • mapValueAsync: <A>(fn: (x: T) => Promise<A>) => MaybeAsync<A>

      transform the value, if any, with an asynchrone operation. If the result of the maping is another Maybe, it will be flatten automatically

    • toPromise: () => Promise<Maybe<T>>

      convert a MybeAsync to a Pomise of Maybe

    • [key: symbol]: true