Skip to content

Commit

Permalink
Make batch generic
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie committed Jun 14, 2024
1 parent 585c9d6 commit ad813d1
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions clients/bigquery/batch.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package bigquery

type Batch struct {
rows []*Row
type Batch[T any] struct {
rows []T
chunkSize int
iteratorIdx int
}

func NewBatch(rows []*Row, chunkSize int) *Batch {
return &Batch{
func NewBatch[T any](rows []T, chunkSize int) *Batch[T] {
return &Batch[T]{
rows: rows,
chunkSize: chunkSize,
}
}

func (b *Batch) HasNext() bool {
func (b *Batch[T]) HasNext() bool {
return len(b.rows) > b.iteratorIdx
}

func (b *Batch) NextChunk() []*Row {
func (b *Batch[T]) NextChunk() []T {
start := b.iteratorIdx
b.iteratorIdx += b.chunkSize
end := b.iteratorIdx
Expand Down

0 comments on commit ad813d1

Please sign in to comment.