chunked method

Iterable<Iterable<T>> chunked(
  1. int chunkSize
)

Splits the Iterable into chunks of a maximum size specified by chunkSize.

Each chunk is yielded as a separate Iterable. If the number of elements is not perfectly divisible by chunkSize, the last chunk will contain the remaining elements.

Example:

final numbers = [1, 2, 3, 4, 5];
final chunks = numbers.chunked(2).toList();
print(chunks); // [[1, 2], [3, 4], [5]]

Implementation

Iterable<Iterable<T>> chunked(int chunkSize) {
  return _chunked<T>(this, chunkSize);
}