flatten method

Option<T> flatten()

Turns Some(Some(value)) into Some(value), and any absence into None.

final flat = const Some<Option<int>>(Some<int>(1)).flatten(); // Some(1)

Implementation

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