feat: 支持件数组数据按照指定数量进行分片

This commit is contained in:
2025-11-27 15:18:42 +08:00
parent 30c1d54f49
commit efdd850e77

View File

@ -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
}