orElse method

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

Returns this option when present, and computes one otherwise.

fallback is not called when this option is present.

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

Implementation

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