Unwraps a Result, computing a fallback value from the error when needed.
The type of the value.
The type of the error.
The Result to unwrap.
A function that receives the error and returns a fallback value.
The unwrapped value or the computed fallback.
const value = unwrapOrElse(ok(42), () => 0);console.log(value); // 42 Copy
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 Copy
const value = unwrapOrElse( err(new Error("Oops")), (error) => error.message.length,);console.log(value); // 4
Unwraps a Result, computing a fallback value from the error when needed.