Files
lo/docs/data/it-buffer.md
T
Adam Szaraniec 56ef3beaf8 feat: support for buffer iterator (#824)
* support for buffer iterator

* Code review fix

* fix: transforming the Buffer helper into a pull-based operator (it receives an iterator instead of channel)

* doc(it): adding loit.Buffer to doc

---------

Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>
2026-03-02 16:07:14 +01:00

827 B

name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
name slug sourceRef category subCategory signatures playUrl variantHelpers similarHelpers position
Buffer buffer it/seq.go#L1162 it sequence
func Buffer[T any](seq iter.Seq[T], size int) iter.Seq[[]T]
it#sequence#buffer
it#sequence#chunk
it#sequence#sliding
it#sequence#window
65

Returns a sequence of slices, each containing up to size items read from the sequence. The last slice may be smaller if the sequence closes before filling the buffer.

Examples:

seq := func(yield func(int) bool) {
    _ = yield(1)
    _ = yield(2)
    _ = yield(3)
    _ = yield(4)
    _ = yield(5)
    _ = yield(6)
    _ = yield(7)
}
buffers := it.Buffer(seq, 3)
var result [][]int
for buffer := range buffers {
    result = append(result, buffer)
}
// result contains [[1 2 3] [4 5 6] [7]]