⬆️ Update vendor

This commit is contained in:
Ettore Di Giacinto
2022-03-21 15:00:51 +01:00
parent 114d4899f6
commit 2f60504da3
38 changed files with 14105 additions and 64 deletions

View File

@@ -2,6 +2,7 @@ package sprig
import (
"fmt"
"math"
"reflect"
"sort"
)
@@ -72,6 +73,50 @@ func mustPrepend(list interface{}, v interface{}) ([]interface{}, error) {
}
}
func chunk(size int, list interface{}) [][]interface{} {
l, err := mustChunk(size, list)
if err != nil {
panic(err)
}
return l
}
func mustChunk(size int, list interface{}) ([][]interface{}, error) {
tp := reflect.TypeOf(list).Kind()
switch tp {
case reflect.Slice, reflect.Array:
l2 := reflect.ValueOf(list)
l := l2.Len()
cs := int(math.Floor(float64(l-1)/float64(size)) + 1)
nl := make([][]interface{}, cs)
for i := 0; i < cs; i++ {
clen := size
if i == cs-1 {
clen = int(math.Floor(math.Mod(float64(l), float64(size))))
if clen == 0 {
clen = size
}
}
nl[i] = make([]interface{}, clen)
for j := 0; j < clen; j++ {
ix := i*size + j
nl[i][j] = l2.Index(ix).Interface()
}
}
return nl, nil
default:
return nil, fmt.Errorf("Cannot chunk type %s", tp)
}
}
func last(list interface{}) interface{} {
l, err := mustLast(list)
if err != nil {