orElse
Pass an Err error to a recovery function returning another Result. An Ok passes through unchanged, without calling recovery. Inspired by Rust's Result::or_else.
Usage
orElse(result, recover)
Parameters
The result to recover. Its error is passed through without normalization.
Called once on failure, or not at all on success. Must return a synchronous Result.
Returns
Result<T | U, F>. The original success or recovery Result is returned by reference. The original error type is replaced by the recovery error type, not automatically retained. To retain the original error, return err(error) from recovery.
Exceptions and async work
Unexpected recovery exceptions propagate; this helper is not a try/catch. Use attempt around throwing recovery work. Async callbacks are not accepted; use an explicit isOk guard when recovery needs to await a Promise.
See also
andThen— continue on success insteadunwrapOr— extract a plain value with a default- Result & Errors