okOrElse<E> method
Converts this Option<T>
into a Result<T, E> using the returned value
from elseFn
if None.
elseFn
will only be evaluated if this Option
is None.
Returns:
- Ok<T, E> if this
Option
is Some<T>. - Err<T, E> using the value returned by
elseFn
if thisOption
is None<T>.
See also:
Rust: Option::ok_or_else()
Implementation
Result<T, E> okOrElse<E>(E Function() elseFn) {
return switch (this) {
Some(:T v) => Ok(v),
None() => Err(elseFn()),
};
}