windowed method
Returns a sliding window of a given size and optional step.
Example:
[1, 2, 3, 4].windowed(2); // [[1, 2], [2, 3], [3, 4]]
Implementation
Iterable<List<T>> windowed(int size, {int step = 1, bool partialWindows = false}) sync* {
final list = toList();
for (var i = 0; i <= list.length - (partialWindows ? 1 : size); i += step) {
final end = (i + size > list.length) ? list.length : i + size;
yield list.sublist(i, end);
}
}