flattenIterable<E> method

  1. @Deprecated('Use flatMap instead')
Iterable<E> flattenIterable<E>(
  1. Iterable<E>? selector(
    1. T item
    )
)

Transforms each element of the iterable into zero or more results of type E, and flattens the resulting collections into a single iterable.

Example:

final numbers = [1, 2, 3];
final doubledNumbers = numbers.flatMapIterable((n) => [n, n * 2]);
// doubledNumbers will be [1, 2, 2, 4, 3, 6]

Implementation

@Deprecated('Use flatMap instead')
Iterable<E> flattenIterable<E>(Iterable<E>? Function(T item) selector) sync* {
  for (T item in this) {
    Iterable<E>? res = selector(item);
    if (res != null) yield* res;
  }
}