--- name: chunk kind: function lang: go domain: core version: "1.0.0" purity: pure signature: "func Chunk[T any](xs []T, size int) [][]T" description: "Divide un slice en trozos (sub-slices) de tamanio N. El ultimo trozo puede contener menos de N elementos. Retorna nil si el slice esta vacio. Entra en panic si size <= 0." tags: [slice, chunk, batch, generic] uses_functions: [] uses_types: [] returns: [] returns_optional: false error_type: "" imports: [] tested: false tests: [] test_file_path: "" file_path: "functions/core/chunk.go" --- ## Ejemplo ```go chunks := Chunk([]int{1, 2, 3, 4, 5}, 2) // chunks = [[1, 2], [3, 4], [5]] chunks = Chunk([]string{"a", "b", "c", "d"}, 4) // chunks = [["a", "b", "c", "d"]] ``` ## Notas Funcion pura generica. Los sub-slices comparten memoria con el slice original (son slices del mismo backing array). Pre-calcula la capacidad del slice de chunks para evitar reasignaciones. Si size es mayor que len(xs), retorna un unico chunk con todos los elementos.