v0.0.383 sq.InsertMultiple
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m15s

This commit is contained in:
2024-02-09 15:17:51 +01:00
parent 885bb53244
commit 30ce8c4b60
7 changed files with 423 additions and 29 deletions

View File

@@ -479,3 +479,33 @@ func JoinString(arr []string, delimiter string) string {
return str
}
// ArrChunk splits the array into buckets of max-size `chunkSize`
// order is being kept.
// The last chunk may contain less than length elements.
//
// (chunkSize == -1) means no chunking
//
// see https://www.php.net/manual/en/function.array-chunk.php
func ArrChunk[T any](arr []T, chunkSize int) [][]T {
if chunkSize == -1 {
return [][]T{arr}
}
res := make([][]T, 0, 1+len(arr)/chunkSize)
i := 0
for i < len(arr) {
right := i + chunkSize
if right >= len(arr) {
right = len(arr)
}
res = append(res, arr[i:right])
i = right
}
return res
}