Skip to content

Latest commit

 

History

History
38 lines (30 loc) · 641 Bytes

README.md

File metadata and controls

38 lines (30 loc) · 641 Bytes

iter

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.