diff --git a/op_array/util.go b/op_array/util.go index 5eec209..2c3627b 100644 --- a/op_array/util.go +++ b/op_array/util.go @@ -144,3 +144,16 @@ func DeepClone[Value any](dataList []Value) []Value { } return res } + +// Shard 将数组按照指定数量进行分片 +func Shard[Value any](dataList []Value, itemShardCount int) [][]Value { + res := make([][]Value, 0) + for i := 0; i < len(dataList); i += itemShardCount { + tmpList := make([]Value, 0) + for j := 0; j < itemShardCount; j++ { + tmpList = append(tmpList, dataList[i+j]) + } + res = append(res, tmpList) + } + return res +}