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

    Class Ok<T>

    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.

    Type Parameters

    • T

      Success (Ok) payload type.

    Implements

    Index

    Constructors

    Properties

    value: T

    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<never, 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

      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 Ok<T2>

      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

      • _

      Parameters

      • _fn: unknown

      Returns this

      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

      • U1
      • U2

      Parameters

      • _defaultValue: U1
      • fn: (value: T) => U2

        Applied to the success value when this result is Ok.

      Returns U2

    • Returns res if this result is Err, otherwise returns this Ok.

      res is evaluated eagerly; prefer orElse for lazy fallbacks.

      Parameters

      • _res: unknown

      Returns this

      this on Ok, or res on Err.