toIterable method

Iterable<T> toIterable()

Returns the present value as a one-element iterable, or an empty one.

final names = [
  ...const Some<String>('John').toIterable(),
  ...const None<String>().toIterable(),
]; // ['John']

Implementation

Iterable<T> toIterable() {
  return switch (this) {
    Some<T>(:final value) => [value],
    None<T>() => const [],
  };
}