Execute the provided callback, wrapping the return value in Ok
.
If there is an exception, return a Err
of whatever the onError
function returns.
const aSuccessfulOperation = () => 2 + 2;
const anOkResult = Result.tryOrElse(
(e) => e,
aSuccessfulOperation
); // => Ok(4)
const thisOperationThrows = () => throw 'Bummer'
const anErrResult = Result.tryOrElse((e) => e, () => {
thisOperationThrows();
}); // => Err('Bummer')
A function that takes e
exception and returns what will
be wrapped in a Result.Err
Execute the provided callback, wrapping the return value in
Ok
. If there is an exception, return aErr
of whatever theonError
function returns.