Unwraps a ResultAsync, computing a fallback value from the error when needed.
The type of the value.
The type of the error.
The ResultAsync to unwrap.
A function that receives the error and returns a fallback value.
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 Copy
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 Copy
const value = await unwrapAsyncOrElse( Promise.resolve(err(new Error("Oops"))), (error) => error.message.length,);console.log(value); // 4
Unwraps a ResultAsync, computing a fallback value from the error when needed.