unwrapOr method

T unwrapOr(
  1. T fallback
)

Returns the present value, or fallback when this option is absent.

final count = const None<int>().unwrapOr(0);
final existing = const Some<int>(7).unwrapOr(0);

Implementation

T unwrapOr(T fallback) {
  return switch (this) {
    Some<T>(:final value) => value,
    None<T>() => fallback,
  };
}