chunked method

Iterable<Set<E>> chunked(
  1. int size
)

Splits the set into chunks of the given size.

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;
  }
}