once memory allocation for batches

Bator Tsyrendylykov 2020-01-15 11:58:54 +03:00
parent caa3b4c6b1
commit a87dff31b0

@ -179,7 +179,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
var batches [][]int
batches := make([][]int, 0, (len(actions) + batchSize - 1) / batchSize)
for batchSize < len(actions) {
actions, batches = actions[batchSize:], append(batches, actions[0:batchSize:batchSize])