zip<T> function

Iterable<List<T>> zip<T>(
  1. Iterable<Iterable<T>> iterables
)

Returns an Iterable of Lists where the nth element in the returned iterable contains the nth element from every Iterable in iterables. The returned Iterable is as long as the shortest Iterable in the argument. If iterables is empty, it returns an empty list.

Implementation

Iterable<List<T>> zip<T>(Iterable<Iterable<T>> iterables) sync* {
  if (iterables.isEmpty) return;
  final iterators = iterables.map((e) => e.iterator).toList(growable: false);
  while (iterators.every((e) => e.moveNext())) {
    yield iterators.map((e) => e.current).toList(growable: false);
  }
}