import { Maybe } from './maybe.js'; import { ResultAsync } from './resultAsync.js'; import { Unit } from './unit.js'; import { ActionOfT, AsyncActionOfT, FunctionOfT, FunctionOfTtoK, MaybeMatcher, MaybeMatcherNoReturn, None, Some } from './utilities.js'; /** * Represents an asynchronous value that might or might not exist */ export declare class MaybeAsync { /** * Creates a new MaybeAsync from the given value * @param value Can be a Promise or Maybe * @returns MaybeAsync */ static from(maybe: Maybe): MaybeAsync; static from(maybePromise: Promise>): MaybeAsync; static from(promise: Promise | None>): MaybeAsync; /** * Creates a new MaybeAsync from the given value * @param value * @returns */ static some(value: Some): MaybeAsync; /** * Creates a new MaybeAsync with no value * @returns */ static none(): MaybeAsync; get hasValue(): Promise; get hasNoValue(): Promise; private value; protected constructor(value: Promise>); /** * Returns the value of the MaybeAsync if it has one, * and the default value if there is none * @param defaultValue */ getValueOrDefault(defaultValue: Some): Promise; /** * Returns the value of the MaybeAsync if it has one, * and returns the result of the factory function if * there is none * @param factory */ getValueOrDefault(factory: FunctionOfT>): Promise; /** * Returns the value of the MaybeAsync and throws * and returns a rejected Promise is there is none * @returns */ getValueOrThrow(): Promise>; pipe(): MaybeAsync; pipe(op1: MaybeAsyncOpFn): MaybeAsync; pipe(op1: MaybeAsyncOpFn, op2: MaybeAsyncOpFn): MaybeAsync; pipe(op1: MaybeAsyncOpFn, op2: MaybeAsyncOpFn, op3: MaybeAsyncOpFn): MaybeAsync; pipe(op1: MaybeAsyncOpFn, op2: MaybeAsyncOpFn, op3: MaybeAsyncOpFn, op4: MaybeAsyncOpFn): MaybeAsync; pipe(op1: MaybeAsyncOpFn, op2: MaybeAsyncOpFn, op3: MaybeAsyncOpFn, op4: MaybeAsyncOpFn, op5: MaybeAsyncOpFn): MaybeAsync; pipe(op1: MaybeAsyncOpFn, op2: MaybeAsyncOpFn, op3: MaybeAsyncOpFn, op4: MaybeAsyncOpFn, op5: MaybeAsyncOpFn, op6: MaybeAsyncOpFn): MaybeAsync; pipe(op1: MaybeAsyncOpFn, op2: MaybeAsyncOpFn, op3: MaybeAsyncOpFn, op4: MaybeAsyncOpFn, op5: MaybeAsyncOpFn, op6: MaybeAsyncOpFn, op7: MaybeAsyncOpFn): MaybeAsync; pipe(op1: MaybeAsyncOpFn, op2: MaybeAsyncOpFn, op3: MaybeAsyncOpFn, op4: MaybeAsyncOpFn, op5: MaybeAsyncOpFn, op6: MaybeAsyncOpFn, op7: MaybeAsyncOpFn, op8: MaybeAsyncOpFn): MaybeAsync; map(projection: FunctionOfTtoK>): MaybeAsync; map(projection: FunctionOfTtoK>>): MaybeAsync; tap(action: ActionOfT): MaybeAsync; tap(action: AsyncActionOfT): MaybeAsync; bind(projection: FunctionOfTtoK>): MaybeAsync; bind(projection: FunctionOfTtoK>): MaybeAsync; match(matcher: MaybeMatcher): Promise; match(matcher: MaybeMatcherNoReturn): Promise; execute(func: ActionOfT): Promise; execute(func: AsyncActionOfT): Promise; or(fallback: Some | FunctionOfT> | Maybe | FunctionOfT> | MaybeAsync | FunctionOfT>): MaybeAsync; toResult(error: Some): ResultAsync; /** * Returns the inner Promise, wrapping Maybe.none if handleError is true * for a rejected Promise, otherwise rejected Promise handling is left up to the caller. * @param handleError * @returns */ toPromise(handleError?: boolean): Promise>; } export type MaybeAsyncOpFn = FunctionOfTtoK, MaybeAsync>;