From cd0187cd78ba11a79fef697b739a8089a0b524f7 Mon Sep 17 00:00:00 2001 From: Nathan <148575555+nathan-artie@users.noreply.github.com> Date: Fri, 18 Oct 2024 14:43:37 -0700 Subject: [PATCH] Reimplement `kafkalib.batched` using `slices.Chunk` --- lib/kafkalib/batch.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/kafkalib/batch.go b/lib/kafkalib/batch.go index a721a407..cbe2d3ef 100644 --- a/lib/kafkalib/batch.go +++ b/lib/kafkalib/batch.go @@ -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))) }