MVFv3 API Documentation
    Preparing search index...

    Interface ResultBase<T, E>

    interface ResultBase<T, E> {
        and: <U>(result: Result<U, E>) => Result<U, E>;
        andThen: <U, F = E>(fn: (value: T) => Result<U, F>) => Result<U, E | F>;
        andThenAsync: <U, F = E>(
            fn: (value: T) => Promise<Result<U, E>>,
        ) => Promise<Result<U, E | F>>;
        error: undefined | null | E;
        inspect: (fn: (value: T) => void) => Result<T, E>;
        inspectErr: (fn: (error: E) => void) => Result<T, E>;
        isErrAnd: (fn: (error: E) => boolean) => this is Err<E>;
        isOkAnd: (fn: (value: T) => boolean) => this is Ok<T>;
        map: <U>(fn: (value: T) => U) => Result<U, E>;
        mapAsync: <U>(fn: (value: T) => Promise<U>) => Promise<Result<U, E>>;
        mapErr: <F>(fn: (error: E) => F) => Result<T, F>;
        mapOr: <U>(fn: (value: T) => U, fallback: U) => U;
        mapOrAsync: <U>(fn: (value: T) => Promise<U>, fallback: U) => Promise<U>;
        mapOrElse: <U>(fn: (value: T) => U, fallback: () => U) => U;
        mapOrElseAsync: <U>(
            fn: (value: T) => Promise<U>,
            fallback: () => Promise<U>,
        ) => Promise<U>;
        or: <U = T, F = E>(result: Result<U, F>) => Result<T | U, E | F>;
        orElse: <U = T, F = E>(
            fn: (error: E) => Result<U, F>,
        ) => Result<T | U, E | F>;
        toString: () => string;
        unwrap: () => T;
        unwrapOr: <V = T>(fallback: T | V) => T | V;
        unwrapOrElse: <V = T>(fn: () => T | V) => T | V;
        value: undefined | null | T;
        err(): Option<E>;
        expect(message: string): T;
        expectErr(message: string): E;
        isErr(): this is Err<E>;
        isOk(): this is Ok<T>;
        iter(): IterableIterator<T>;
        ok(): Option<T>;
    }

    Type Parameters

    • T
    • E

    Hierarchy

    • Iterable<T>
      • ResultBase
    Index

    Properties

    and: <U>(result: Result<U, E>) => Result<U, E>

    Returns the passed value if this is Ok, otherwise returns this.

    andThen: <U, F = E>(fn: (value: T) => Result<U, F>) => Result<U, E | F>

    Maps a Result<T, E> to Result<U, E | F> by applying a function to a contained Ok value, producing a new result.

    andThenAsync: <U, F = E>(
        fn: (value: T) => Promise<Result<U, E>>,
    ) => Promise<Result<U, E | F>>

    Maps a Result<T, E> to Promise<Result<U, E | F>> by applying a function to a contained Ok value, producing a new async result.

    error: undefined | null | E

    The error, if available.

    inspect: (fn: (value: T) => void) => Result<T, E>

    Allows inspection of the interior result value, if it is Ok. May be useful in cases where you do not want to modify the result.

    inspectErr: (fn: (error: E) => void) => Result<T, E>

    Allows inspection of the interior error value, if it is Err. May be useful in cases where you do not want to modify the error.

    isErrAnd: (fn: (error: E) => boolean) => this is Err<E>

    Asserts that the current result is Err and the error passes the given predicate.

    isOkAnd: (fn: (value: T) => boolean) => this is Ok<T>

    Asserts that the current result is Ok and the value passes the given predicate.

    map: <U>(fn: (value: T) => U) => Result<U, E>

    Maps a Result<T, E> to Result<U, E> by applying a function to a contained Ok value, leaving the Err value untouched.

    mapAsync: <U>(fn: (value: T) => Promise<U>) => Promise<Result<U, E>>

    Maps a Result<T, E> to Promise<Result<U, E>> by applying a function to a contained Ok value, leaving the Err value untouched.

    mapErr: <F>(fn: (error: E) => F) => Result<T, F>

    Maps a Result<T, E> to Result<T, F> by applying a function to a contained Err value, leaving the Ok value untouched.

    mapOr: <U>(fn: (value: T) => U, fallback: U) => U

    Maps a Result<T, E> to U by applying a function to a contained Ok value. If the result is an Err, the fallback value will be returned.

    mapOrAsync: <U>(fn: (value: T) => Promise<U>, fallback: U) => Promise<U>

    Maps a Result<T, E> to Promise by applying a function to a contained Ok value. If the result is an Err, the fallback value will be returned.

    mapOrElse: <U>(fn: (value: T) => U, fallback: () => U) => U

    Maps a Result<T, E> to U by applying a function to a contained Ok value. If the result is an Err, the fallback function will be called and its result will be returned.

    mapOrElseAsync: <U>(
        fn: (value: T) => Promise<U>,
        fallback: () => Promise<U>,
    ) => Promise<U>

    Maps a Result<T, E> to Promise by applying a function to a contained Ok value. If the result is an Err, the fallback function will be called and its result will be returned.

    or: <U = T, F = E>(result: Result<U, F>) => Result<T | U, E | F>

    Returns the passed value if this is Err, otherwise returns this.

    orElse: <U = T, F = E>(fn: (error: E) => Result<U, F>) => Result<T | U, E | F>

    Calls fn if the result is an Err, otherwise returns this.

    toString: () => string

    Returns a string representation of the result for debugging purposes.

    unwrap: () => T

    Returns the inner value of a result, if it is Ok. Otherwise, the contained error will be thrown.

    USE THIS SPARINGLY! It is generally better to use unwrapOr or map to handle situations you may be temped to .unwrap() in.

    The contained error, if the result is an Err.

    unwrapOr: <V = T>(fallback: T | V) => T | V

    Returns the inner value of a result, if it is Ok. Otherwise, the provided fallback value will be returned.

    unwrapOrElse: <V = T>(fn: () => T | V) => T | V

    Returns the inner value of a result, if it is Ok. Otherwise, the provided fallback funtion will be called and its result will be returned.

    value: undefined | null | T

    The good value, if available.

    Methods

    • Returns an option of the inner error of a result.

      Returns Option<E>

    • Unwraps a result, yielding the value.

      USE THIS SPARINGLY! It is generally better to use unwrapOr or map to handle situations you may be temped to .expect() in.

      This is good for using in tests.

      Parameters

      • message: string

      Returns T

      A new error with the provided message, if the result is an Err.

    • Unwraps a result, yielding the error.

      USE THIS SPARINGLY! It is generally better to use unwrapOr or map to handle situations you may be temped to .expect() in.

      This is good for using in tests.

      Parameters

      • message: string

      Returns E

      A new error with the provided message, if the result is an Ok.

    • Asserts that the current result is Err.

      Returns this is Err<E>

    • Asserts that the current result is Ok.

      Returns this is Ok<T>

    • Returns IterableIterator<T>

    • Returns an option of the inner value of a result.

      Returns Option<T>