chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,36 @@
|
||||
package utils
|
||||
|
||||
// ChunkSlice splits a slice into multiple sub-slices of the specified size
|
||||
func ChunkSlice[T any](slice []T, chunkSize int) [][]T {
|
||||
// Handle edge cases
|
||||
if len(slice) == 0 {
|
||||
return [][]T{}
|
||||
}
|
||||
|
||||
if chunkSize <= 0 {
|
||||
panic("chunkSize must be greater than 0")
|
||||
}
|
||||
|
||||
// Calculate how many sub-slices are needed
|
||||
chunks := make([][]T, 0, (len(slice)+chunkSize-1)/chunkSize)
|
||||
|
||||
// Split the slice
|
||||
for i := 0; i < len(slice); i += chunkSize {
|
||||
end := i + chunkSize
|
||||
if end > len(slice) {
|
||||
end = len(slice)
|
||||
}
|
||||
chunks = append(chunks, slice[i:end])
|
||||
}
|
||||
|
||||
return chunks
|
||||
}
|
||||
|
||||
// MapSlice applies a function to each element of a slice and returns a new slice with the results
|
||||
func MapSlice[A any, B any](in []A, f func(A) B) []B {
|
||||
out := make([]B, 0, len(in))
|
||||
for _, item := range in {
|
||||
out = append(out, f(item))
|
||||
}
|
||||
return out
|
||||
}
|
||||
Reference in new issue
Block a user