Evercatch - v0.9.0
    Preparing search index...

    Function unwrapOrElse

    • Unwraps a Result, computing a fallback value from the error when needed.

      Type Parameters

      • T

        The type of the value.

      • E = Error

        The type of the error.

      Parameters

      • result: Result<T, E>

        The Result to unwrap.

      • fallbackFn: (err: E) => T

        A function that receives the error and returns a fallback value.

      Returns T

      The unwrapped value or the computed fallback.

      const value = unwrapOrElse(ok(42), () => 0);
      console.log(value); // 42
      const value = unwrapOrElse(
      err(new Error("Oops")),
      (error) => error.message.length,
      );
      console.log(value); // 4