chunked method
Splits the iterable into chunks of size.
[1,2,3,4,5].chunked(2) // [[1,2],[3,4],[5]]
Implementation
Iterable<List<T>> chunked(int size) sync* {
assert(size > 0, 'chunk size must be > 0');
var chunk = <T>[];
for (final e in this) {
chunk.add(e);
if (chunk.length == size) {
yield chunk;
chunk = [];
}
}
if (chunk.isNotEmpty) yield chunk;
}