Skip to content

Commit

Permalink
Reimplement kafkalib.batched using slices.Chunk (#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie authored Oct 18, 2024
1 parent 9082ca1 commit caad3d1
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions lib/kafkalib/batch.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package kafkalib

import "slices"

// batched splits a slice of items into a slice of step-sized slices.
func batched[T any](items []T, step int) [][]T {
step = max(step, 1)
var result [][]T
for index := 0; index < len(items); {
end := min(index+step, len(items))
result = append(result, items[index:end])
index = end
}
return result
return slices.Collect(slices.Chunk(items, max(step, 1)))
}

0 comments on commit caad3d1

Please sign in to comment.