batch slice cap should be actions divided by batchSize and plus one for remainder (added braces for clarity)

Wei Zhang 2020-06-08 21:10:44 +01:00
parent 0f386c514f
commit 46fe561bef

@ -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])