Evercatch - v0.9.0
    Preparing search index...

    Function unwrapAsyncOr

    • Unwraps a ResultAsync, returning a fallback value if it contains an error.

      Type Parameters

      • T

        The type of the value.

      • E = Error

        The type of the error.

      Parameters

      • resultAsync: ResultAsync<T, E>

        The ResultAsync to unwrap.

      • fallback: T

        The value to return when the result contains an error.

      Returns Promise<T>

      A promise that resolves to the unwrapped value or the fallback.

      const value = await unwrapAsyncOr(Promise.resolve(ok(42)), 0);
      console.log(value); // 42
      const value = await unwrapAsyncOr(
      Promise.resolve(err(new Error("Oops"))),
      0,
      );
      console.log(value); // 0