@tempots/std
AsyncResult variable
A set of utility functions for working with AsyncResult
.
Signature:
AsyncResult: {
notAsked: {
type: "NotAsked";
};
loading(previousValue?: Maybe): AsyncResultnever>;
success(value: V): AsyncResultnever>;
failure(error: E): AsyncResult<never, E>;
isSuccess(r: AsyncResult): r is AsyncSuccess;
isFailure(r: AsyncResult): r is AsyncFailure;
isNotAsked(r: AsyncResult): r is NotAsked;
isLoading(r: AsyncResult): r is Loading;
getOrElse(r: AsyncResult, alt: V): V;
getOrElseLazy(r: AsyncResult, altf: () => V): V;
getOrNull(r: AsyncResult): V | null;
getOrUndefined(r: AsyncResult): Maybe;
getUnsafe: (r: AsyncResult) => V;
match: <V1, V2, E>(r: AsyncResult<V1, E>, { success, failure, loading, notAsked, }: {
success: (value: V1) => V2;
failure: (error: E) => V2;
loading: (previousValue?: V1) => V2;
notAsked: () => V2;
}) => V2;
whenSuccess: (r: AsyncResult, apply: (v: V) => void) => AsyncResult;
whenFailure: (r: AsyncResult, apply: (e: E) => void) => AsyncResult;
equals: (r1: AsyncResult, r2: AsyncResult, options?: {
valueEquals: (v1: V, v2: V) => boolean;
errorEquals: (e1: E, e2: E) => boolean;
}) => boolean;
all: (results: AsyncResult[]) => AsyncResult;
ofPromise: (p: Promise) => Promise<AsyncResultError>>;
}