orElse method

Option<T> orElse(
  1. Option<T> fn()
)

Returns this Option if this Option is Some<T>, otherwise calls fn and returns the returned Option.

See also: Rust: Option::or_else()

Implementation

Option<T> orElse(Option<T> Function() fn) {
  return switch (this) {
    Some() => this,
    None() => fn(),
  };
}