windowed method
Returns a Iterable
of snapshots of the window of the given size
sliding along this collection with the given step
, where each snapshot
is a Iterable
.
Implementation
Iterable<Iterable<E>> windowed({
required int size,
int step = 1,
bool partialWindows = false,
}) {
if (size <= 0) {
throw ArgumentError.value(size, 'size', 'must be greater than zero');
}
if (step <= 0) {
throw ArgumentError.value(step, 'step', 'must be greater than zero');
}
final length = partialWindows
? (this.length / step).ceil()
: (this.length - size) ~/ step + 1;
return Iterable.generate(
length,
(index) => skip(index * step).take(size),
);
}