Note
This repository is archived and no longer maintained.
It provided iterator utilities for Go before the language had native
iterator support. As of Go 1.23, range-over-func and the standard library
iter package provide first-class iterators,
and helpers such as slices.Chunk
cover the batched-slice use case. Prefer those for new code.
The content is kept for historical reference only.
Iterator utils for Go.
import "golang.design/x/iter"it := iter.NewBatchFromSlice[T](s, 42)
for batch, ok := it.Next(); ok; batch, ok = it.Next() {
// do something with batch
}it := NewGormIter[T](tx, batchSize)
for batch, ok := it.Next(); ok; batch, ok = it.Next() {
// Process the batch.
...
// Stop the iteration if necessary.
if ... {
it.Stop()
break
}
}
if err := it.Err(); err != nil {
// Handle the error.
}MIT | © 2023 The golang.design Initiative Authors, written by Changkun Ou.