zip method
Combines the first, second, third, ... elements of each Iterable into a new list. The resulting iterable has the length of the shortest input iterable.
The following expression yields [1, 'a']
and [2, 'b']
:
[[1, 2], ['a', 'b']].zip();
Implementation
Iterable<List<E>> zip() sync* {
if (isEmpty) return;
final iterators =
map((iterable) => iterable.iterator).toList(growable: false);
for (;;) {
final result = <E>[];
for (final iterator in iterators) {
if (iterator.moveNext()) {
result.add(iterator.current);
} else {
return;
}
}
yield result;
}
}