unwrap method

T unwrap()

Returns the present value, or throws when absent.

Throws a StateError for None. Prefer expect where the reason a value must exist is worth saying, and Option.unwrapOr where it need not exist at all.

final id = const Some<int>(7).unwrap(); // 7

Implementation

T unwrap() {
  return switch (this) {
    Some<T>(:final value) => value,
    None<T>() => throw StateError('called unwrap() on None'),
  };
}