新增一系列数组操作的工具函数 #12

Merged
zhangdeman merged 8 commits from feature/arr_util into master 2025-12-04 10:49:44 +08:00
4 changed files with 233 additions and 0 deletions
Showing only changes of commit efdd850e77 - Show all commits

View File

@ -144,3 +144,16 @@ func DeepClone[Value any](dataList []Value) []Value {
} }
return res 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
}