chunked method

Iterable<Characters> chunked(
  1. int size
)

Divides these Characters into an iterable of characters each not exceeding the given size. The last string might have fewer characters.

For example:

final input = 'abcde';
print(input.chunked(2));  // ('ab', 'cd', 'e')

Implementation

Iterable<Characters> chunked(int size) sync* {
  checkNonZeroPositive(size);
  final range = iterator;
  while (range.moveNext(size)) {
    yield range.currentCharacters;
  }
  if (range.isNotEmpty) {
    yield range.currentCharacters;
  }
}