chunked method

Iterable<List<T>> chunked(
  1. int size
)

Returns chunks of the specified size

Implementation

Iterable<List<T>> chunked(int size) sync* {
  if (size <= 0) throw ArgumentError('Size must be positive');
  final it = iterator;
  while (it.moveNext()) {
    final chunk = <T>[it.current];
    for (int i = 1; i < size && it.moveNext(); i++) {
      chunk.add(it.current);
    }
    yield chunk;
  }
}