windowed
Sliding windows of size consecutive elements, each starting step elements after the last.
Lecture
chunk cuts a sequence into
non-overlapping pieces. The moment the pieces must overlap —
a moving average, "three consecutive readings over the limit", any
each-element-with-its-neighbors question — you end up hand-rolling an
index loop with careful bounds. windowed(size) is that
loop as a lazy operator: it yields a List of each
size consecutive elements, sliding forward by
step (default 1) between windows.
Two knobs cover the whole family. step spaces the
windows: step < size overlaps them,
step == size tiles them exactly like
chunk, and step > size samples
with gaps. partial: true keeps the shorter windows
at the tail instead of dropping them — in fact
chunk(n) is
windowed(n, step: n, partial: true); they share
one implementation.
fxdart extension (no FxTS counterpart) — named after Kotlin's
windowed; RxDart readers know it as
bufferCount(size, startEvery). It is lazy like every
fxdart operator: windows materialize one pull at a time, so it
composes with endless sources and with
concurrent.
Demo 1 · Moving average
Demo 2 · The step & partial knobs
Try it yourself
Exercise: flag three consecutive days over the spending limit.