feat: 6 funciones core — retry, memoize, pipeline, map_concurrent, partition, chunk

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>
This commit is contained in:
2026-03-28 02:23:26 +01:00
parent 0f9a72dfc9
commit 16e34a806e
12 changed files with 362 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
---
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.