or method
If this result is Ok, then returns it as is.
If this result is Err, then call result = f()
.
If result of call f() is null, then returns Err.
If result of call f() is value , then return Ok(value).
If call of f() throws exception, then returns Err.
Implementation
Result<T> or(T? Function() f) {
if (isOk) {
return this;
}
try {
var res = f();
if (res == null) {
return Err<T>(StateError('Result of f() == null, where `f` is $f'));
}
return Ok<T>(res);
} catch (e) {
return Err(StateError('Raised exception $e while called $f'));
}
}