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) => switch (this) {
Some(value: T value) => Ok(value),
None() => Err(elseFn())
};