From 46fe561befe97672f770640f831a9a545c77e540 Mon Sep 17 00:00:00 2001 From: Wei Zhang Date: Mon, 8 Jun 2020 21:10:44 +0100 Subject: [PATCH] batch slice cap should be actions divided by batchSize and plus one for remainder (added braces for clarity) --- SliceTricks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SliceTricks.md b/SliceTricks.md index 3441faa2..2f50d755 100644 --- a/SliceTricks.md +++ b/SliceTricks.md @@ -177,7 +177,7 @@ Useful if you want to do batch processing on large slices. ```go actions := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} batchSize := 3 -batches := make([][]int, 0, (len(actions) + batchSize - 1) / batchSize) +batches := make([][]int, 0, (len(actions) / batchSize + 1)) for batchSize < len(actions) { actions, batches = actions[batchSize:], append(batches, actions[0:batchSize:batchSize])