partition method
Implementation
Iterable<List<T>> partition(int size) sync* {
Iterator<T> iterator = this.iterator;
if (!iterator.moveNext()) return;
T previous = iterator.current;
List<T> chunk = [previous];
int index = 0;
while (iterator.moveNext()) {
T element = iterator.current;
if (++index % size == 0) {
yield chunk;
chunk = [];
}
chunk.add(element);
previous = element;
}
yield chunk;
}