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:
@@ -0,0 +1,16 @@
|
||||
package core
|
||||
|
||||
// Memoize wraps a pure function fn so that results are cached by key.
|
||||
// Subsequent calls with the same key return the cached value without calling fn again.
|
||||
// The returned function is safe for single-goroutine use.
|
||||
func Memoize[K comparable, V any](fn func(K) V) func(K) V {
|
||||
cache := make(map[K]V)
|
||||
return func(key K) V {
|
||||
if val, ok := cache[key]; ok {
|
||||
return val
|
||||
}
|
||||
val := fn(key)
|
||||
cache[key] = val
|
||||
return val
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user