Evercatch - v0.10.0
    Preparing search index...

    Variable unwrapOrElseReadonly

    unwrapOrElse: <T, E extends unknown = Error>(
        resultAsync: ResultAsync<T, E>,
        fallbackFn: (err: E) => T,
    ) => Promise<T> = unwrapAsyncOrElse

    Type declaration

      • <T, E extends unknown = Error>(
            resultAsync: ResultAsync<T, E>,
            fallbackFn: (err: E) => T,
        ): Promise<T>
      • Unwraps a ResultAsync, computing a fallback value from the error when needed.

        Type Parameters

        • T

          The type of the value.

        • E extends unknown = Error

          The type of the error.

        Parameters

        • resultAsync: ResultAsync<T, E>

          The ResultAsync to unwrap.

        • fallbackFn: (err: E) => T

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

        Returns Promise<T>

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

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