16e34a806e
Funciones genericas reutilizables: - RetryWithBackoff: reintento con backoff exponencial (impure) - Memoize: cache de funciones puras (pure) - Pipeline: composición T→T en secuencia (pure) - MapConcurrent: map paralelo con worker pool (impure) - Partition: divide slice en dos por predicado (pure) - Chunk: divide slice en trozos de tamaño N (pure) Todas con implementación real y documentación .md. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1002 B
1002 B
name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, tested, tests, test_file_path, file_path
| name | kind | lang | domain | version | purity | signature | description | tags | uses_functions | uses_types | returns | returns_optional | error_type | imports | tested | tests | test_file_path | file_path | ||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| chunk | function | go | core | 1.0.0 | pure | func Chunk[T any](xs []T, size int) [][]T | 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. |
|
false | false | functions/core/chunk.go |
Ejemplo
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.