Safely get the value out of a Result by returning the wrapped
value if it is Ok, or by applying orElseFn to the value in the
Err.
This is useful when you need to generate a value (e.g. by using current
values in the environment – whether preloaded or by local closure) instead of
having a single default value available (as in unwrapOr).
// You can imagine that someOtherValue might be dynamic. constsomeOtherValue = 2; consthandleErr = (errValue: string) =>errValue.length + someOtherValue;
Safely get the value out of a
Result
by returning the wrapped value if it isOk
, or by applyingorElseFn
to the value in theErr
.This is useful when you need to generate a value (e.g. by using current values in the environment – whether preloaded or by local closure) instead of having a single default value available (as in
unwrapOr
).