or method

Option<T> or(
  1. Option<T> other
)

Returns this option when present, and other otherwise.

other is evaluated before the call. Use orElse when computing it is expensive or has side effects.

final name = const None<String>().or(const Some<String>('guest'));

Implementation

Option<T> or(Option<T> other) {
  return switch (this) {
    Some<T>() => this,
    None<T>() => other,
  };
}