always-panic - v0.10.1
    Preparing search index...

    Interface ResultBase<T, E>

    Method contract shared by Ok and Err, aligned with Rust std::result::Result.

    Result<T, E> is either success (Ok(T)) or failure (Err(E)). Implementations mirror the Rust combinator names and semantics; on failure, expect / unwrap / unwrapErr throw a JavaScript Error instead of panicking.

    interface ResultBase<T, E> {
        "[iterator]"(): Generator<Err<E>, T>;
        and<R extends Result<OkContent<R>, ErrContent<R>>>(
            res: R,
        ): ResultBase<T, E> | R;
        andThen<R extends Result<OkContent<R>, ErrContent<R>>>(
            fn: (value: T) => R,
        ): ResultBase<T, E> | R;
        expect(message: string): T;
        inspect(fn: (value: DeepReadonly<T>) => void): this;
        inspectErr(fn: (error: DeepReadonly<E>) => void): this;
        isErr(): boolean;
        isOk(): boolean;
        map<T2>(fn: (value: T) => T2): Result<T2, E>;
        mapErr<E2>(fn: (error: E) => E2): Result<T, E2>;
        mapOr<T2>(defaultValue: T2, fn: (value: T) => T2): T2;
        mapOrElse<T2>(onErr: (error: E) => T2, onOk: (value: T) => T2): T2;
        or<R extends Result<OkContent<R>, ErrContent<R>>>(
            res: R,
        ): ResultBase<T, E> | R;
        orElse<R extends Result<OkContent<R>, ErrContent<R>>>(
            fn: (error: E) => R,
        ): ResultBase<T, E> | R;
        unwrap(): T;
        unwrapErr(): E;
        unwrapOr<T2>(defaultValue: T2): T | T2;
        unwrapOrElse<T2>(fn: (error: E) => T2): T | T2;
    }

    Type Parameters

    • T

      Success (Ok) payload type.

    • E

      Error (Err) payload type.

    Implemented by

    Index

    Methods

    • Enables yield* res inside a result.gen body — the equivalent of Rust's ? operator.

      On Ok, yield* produces no yields and evaluates to the contained value. On Err, it yields the Err itself, which the surrounding result.gen / genSync / genAsync driver returns by reference (short-circuiting the rest of the body). Not meant to be iterated by anything other than those drivers.

      Returns Generator<Err<E>, T>

    • Returns the contained Ok value.

      Prefer narrowing (isOk / isErr) or non-throwing helpers (unwrapOr, unwrapOrElse) when the Err case is expected.

      Parameters

      • message: string

        Included in the thrown Error when this result is Err (describe why you expected Ok, as in Rust's expect docs).

      Returns T

      The success value.

      When the result is Err.

    • Maps Result<T, E> to Result<U, E> by applying fn to the contained Ok value, leaving an Err untouched.

      Type Parameters

      • T2

      Parameters

      • fn: (value: T) => T2

        Transforms the success value.

      Returns Result<T2, E>

      A new Result with the mapped Ok value, or the original Err.

    • Maps Result<T, E> to Result<T, F> by applying fn to the contained Err value, leaving an Ok untouched.

      Type Parameters

      • E2

      Parameters

      • fn: (error: E) => E2

        Transforms the error value.

      Returns Result<T, E2>

      A new Result with the mapped Err value, or the original Ok.

    • Returns defaultValue if Err, or applies fn to the contained Ok value.

      Both arguments are evaluated eagerly; prefer mapOrElse when the fallback should run only on Err.

      Type Parameters

      • T2

      Parameters

      • defaultValue: T2

        Value returned when this result is Err.

      • fn: (value: T) => T2

        Applied to the success value when this result is Ok.

      Returns T2

    • Maps a Result to U by applying onErr to a contained Err value, or onOk to a contained Ok value.

      Type Parameters

      • T2

      Parameters

      • onErr: (error: E) => T2

        Called with the error when this result is Err.

      • onOk: (value: T) => T2

        Called with the success value when this result is Ok.

      Returns T2

    • Returns the contained Ok value, or defaultValue if the result is Err.

      Type Parameters

      • T2

      Parameters

      • defaultValue: T2

        Value to return when this result is Err (evaluated eagerly).

      Returns T | T2

      T on Ok, otherwise defaultValue.

    • Returns the contained Ok value, or computes it from the Err value.

      Type Parameters

      • T2

      Parameters

      • fn: (error: E) => T2

        Called with the error when this result is Err.

      Returns T | T2

      T on Ok, otherwise the value returned by fn.