Skip to content
This repository was archived by the owner on Jun 7, 2026. It is now read-only.

golang-design/iter

Repository files navigation

iter

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"

Batched Slice Iterator

it := iter.NewBatchFromSlice[T](s, 42)
for batch, ok := it.Next(); ok; batch, ok = it.Next() {
    // do something with batch
}

Batched gorm Iterator

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.
}

License

MIT | © 2023 The golang.design Initiative Authors, written by Changkun Ou.

About

Iterator utils.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages