flatten method

  1. @lazy
  2. @useResult
Iterable<E> flatten()

Returns a lazy iterable that flattens all nested iterables in this iterable.

This function is non-deterministic when this iterable or its nested iterables are unordered, i.e. HashSet.

final nested = [[1, 2], [3, 4], [5]];
print(nested.flatten()); // [1, 2, 3, 4, 5]

Implementation

@lazy @useResult Iterable<E> flatten() sync* {
  for (final iterable in this) {
    for (final element in iterable) {
      yield element;
    }
  }
}