Files
grafana/pkg/services/cloudmigration/slicesext/slicesext.go
Bruno d1952bb681 Cloud migrations: create snapshot files (#89693)
* Cloud migrations: create snapshot and store it on disk

* fix merge conflicts

* implement StartSnapshot for gms client

* pass snapshot directory as argument to snapshot builder

* ensure snapshot folder is set

* make swagger-gen

* remove Test_ExecuteAsyncWorkflow

* pass signed in user to buildSnapshot method / use github.com/grafana/grafana-cloud-migration-snapshot to create snapshot files

* fix FakeServiceImpl.CreateSnapshot

* remove new line
2024-07-03 10:38:26 -03:00

34 lines
631 B
Go

package slicesext
import "math"
// Partitions the input into slices where the length is <= chunkSize.
//
// Example:
//
// Chunks(2, []int{1, 2, 3, 4})
// => [][]int{{1, 2}, {3, 4}}
func Chunks[T any](chunkSize int, xs []T) [][]T {
if chunkSize < 0 {
panic("chunk size must be greater than or equal to 0")
}
if chunkSize == 0 {
return [][]T{}
}
out := make([][]T, 0, int(math.Ceil(float64(len(xs))/float64(chunkSize))))
for i := 0; i < len(xs); i += chunkSize {
var chunk []T
if i+chunkSize < len(xs) {
chunk = xs[i : i+chunkSize]
} else {
chunk = xs[i:]
}
out = append(out, chunk)
}
return out
}