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

Merged
zhangdeman merged 8 commits from feature/arr_util into master 2025-12-04 10:49:44 +08:00
efdd850e77 feat: 支持件数组数据按照指定数量进行分片
白茶清欢
2025-11-27 15:18:42 +08:00
Commit 8 of 8
Show all commits
+13
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
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.