v0.0.383 sq.InsertMultiple
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m15s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m15s
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user