@tempots/std

Result variable

Utility functions for working with Result types.

Signature:

Result: {
    success(value: V): Resultany>;
    failure(error: E): Result<any, E>;
    map: <V1, V2, E>(r: Result<V1, E>, f: (value: V1) => V2) => Result<V2, E>;
    flatMap: <V1, V2, E>(r: Result<V1, E>, f: (value: V1) => Result<V2, E>) => Result<V2, E>;
    toAsync(r: Result): AsyncResult;
    toValidation(r: Result): Validation;
    isSuccess(r: Result): r is Success;
    isFailure(r: Result): r is Failure;
    getOrElse(r: Result, alt: V): V;
    getOrElseLazy(r: Result, altf: () => V): V;
    getOrNull(r: Result): V | null;
    getOrUndefined(r: Result): Maybe;
    getUnsafe: (r: Result) => V;
    match: <V1, V2, E>(r: Result<V1, E>, success: (value: V1) => V2, failure: (error: E) => V2) => V2;
    whenSuccess: (r: Result, apply: (v: V) => void) => Result;
    whenFailure: (r: Result, apply: (e: E) => void) => Result;
    combine: (r1: Result, r2: Result, combineV: (v1: V, v2: V) => V, combineE: (e1: E, e2: E) => E) => Result;
    equals: (r1: Result, r2: Result, options?: {
        valueEquals: (v1: V, v2: V) => boolean;
        errorEquals: (e1: E, e2: E) => boolean;
    }) => boolean;
    all: (results: Result[]) => Result;
}