Back to Lo

It Window

docs/data/it-window.md

1.53.0382 B
Original Source

Creates a sequence of sliding windows of a given size. Each window overlaps with the previous one by size-1 elements.

go
seq := func(yield func(int) bool) {
    yield(1)
    yield(2)
    yield(3)
    yield(4)
    yield(5)
}
windows := it.Window(seq, 3)
var result [][]int
for w := range windows {
    result = append(result, w)
}
// result contains [1 2 3], [2 3 4], [3 4 5]