Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie committed Mar 30, 2024
1 parent 7b1ee9a commit 667188d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/iterator/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type batchIterator[T any] struct {
}

// Returns an iterater that splits a list of items into batches of the given step size.
func Batch[T any](items []T, step int) Iterator[[]T] {
func NewBatchIterator[T any](items []T, step int) Iterator[[]T] {
return &batchIterator[T]{
items: items,
index: 0,
Expand Down
12 changes: 6 additions & 6 deletions lib/iterator/iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import (
"github.com/stretchr/testify/assert"
)

func TestBatch(t *testing.T) {
func TestBatchIterator(t *testing.T) {
// length of items is 0
{
iter := Batch([]int{}, 2)
iter := NewBatchIterator([]int{}, 2)
assert.False(t, iter.HasNext())
_, err := iter.Next()
assert.ErrorContains(t, err, "iterator has finished")
}
// length of items is 1
{
iter := Batch([]int{1}, 2)
iter := NewBatchIterator([]int{1}, 2)
assert.True(t, iter.HasNext())
{
items, err := iter.Next()
Expand All @@ -31,7 +31,7 @@ func TestBatch(t *testing.T) {
}
// n is 0
{
iter := Batch([]int{1, 2}, 0)
iter := NewBatchIterator([]int{1, 2}, 0)
assert.True(t, iter.HasNext())
items, err := iter.Next()
assert.NoError(t, err)
Expand All @@ -43,7 +43,7 @@ func TestBatch(t *testing.T) {
}
// length of items is a multiple of n
{
iter := Batch([]int{1, 2, 3, 4}, 2)
iter := NewBatchIterator([]int{1, 2, 3, 4}, 2)
assert.True(t, iter.HasNext())
{
items, err := iter.Next()
Expand All @@ -64,7 +64,7 @@ func TestBatch(t *testing.T) {
}
// length of items is not a multiple of n
{
iter := Batch([]int{1, 2, 3, 4, 5}, 2)
iter := NewBatchIterator([]int{1, 2, 3, 4, 5}, 2)
assert.True(t, iter.HasNext())
{
items, err := iter.Next()
Expand Down
2 changes: 1 addition & 1 deletion lib/kafkalib/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (b *BatchWriter) WriteMessages(ctx context.Context, msgs []kafka.Message) e
return nil
}

iter := iterator.Batch(msgs, int(chunkSize))
iter := iterator.NewBatchIterator(msgs, int(chunkSize))
for iter.HasNext() {
tags := map[string]string{
"what": "error",
Expand Down

0 comments on commit 667188d

Please sign in to comment.