Execute the provided callback, wrapping the return value in Ok. If there is an exception, return a Err of whatever the onError function returns.
Ok
Err
onError
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') Copy
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
e
Result.Err
The callback to try executing
Generated using TypeDoc
Execute the provided callback, wrapping the return value in
Ok
. If there is an exception, return aErr
of whatever theonError
function returns.