chunked method
Splits the set into chunks of the given size
.
Example:
final set = {1, 2, 3, 4, 5};
print(set.chunked(2)); // ({1, 2}, {3, 4}, {5})
Implementation
Iterable<Set<E>> chunked(int size) sync* {
if (size <= 0) throw ArgumentError('Size must be positive');
final iterator = this.iterator;
while (iterator.moveNext()) {
final chunk = <E>{};
do {
chunk.add(iterator.current);
} while (chunk.length < size && iterator.moveNext());
yield chunk;
}
}