feat: 21 funciones core — composicion funcional y operaciones de slice

Composicion: Pipe2, Pipe3, Compose2, Identity, Curry2, Uncurry2, Partial2,
Flip, Const. Slices: Find, FindIndex, Any, All, GroupBy, Flatten,
FlatMapSlice, Unique, Zip, Reduce, Take, Drop.
Stubs que documentan devfactory/core para el registry.
This commit is contained in:
2026-03-28 03:58:17 +01:00
parent 62dcadceb8
commit 133982cfaf
42 changed files with 877 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
package core
// Implementation: github.com/lucasdataproyects/devfactory/core
// All devuelve true si todos los elementos del slice cumplen el predicado.
func All[T any](slice []T, predicate func(T) bool) bool {
// stub
return false
}
+32
View File
@@ -0,0 +1,32 @@
---
name: all_slice
kind: function
lang: go
domain: core
version: "1.0.0"
purity: pure
signature: "func All[T any](slice []T, predicate func(T) bool) bool"
description: "Devuelve true si todos los elementos del slice cumplen el predicado."
tags: [slice, functional, generic, predicate]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "functions/core/all_slice.go"
---
## Ejemplo
```go
result := All([]int{2, 4, 6}, func(x int) bool { return x%2 == 0 })
// result = true
```
## Notas
Funcion pura generica. Implementacion en devfactory/core.
+9
View File
@@ -0,0 +1,9 @@
package core
// Implementation: github.com/lucasdataproyects/devfactory/core
// Any devuelve true si al menos un elemento del slice cumple el predicado.
func Any[T any](slice []T, predicate func(T) bool) bool {
// stub
return false
}
+32
View File
@@ -0,0 +1,32 @@
---
name: any_slice
kind: function
lang: go
domain: core
version: "1.0.0"
purity: pure
signature: "func Any[T any](slice []T, predicate func(T) bool) bool"
description: "Devuelve true si al menos un elemento del slice cumple el predicado."
tags: [slice, functional, generic, predicate]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "functions/core/any_slice.go"
---
## Ejemplo
```go
result := Any([]int{1, 2, 3}, func(x int) bool { return x > 2 })
// result = true
```
## Notas
Funcion pura generica. Implementacion en devfactory/core.
+9
View File
@@ -0,0 +1,9 @@
package core
// Implementation: github.com/lucasdataproyects/devfactory/core
// Compose2 compone dos funciones de derecha a izquierda.
func Compose2[A, B, C any](f2 func(B) C, f1 func(A) B) func(A) C {
// stub
return nil
}
+34
View File
@@ -0,0 +1,34 @@
---
name: compose2
kind: function
lang: go
domain: core
version: "1.0.0"
purity: pure
signature: "func Compose2[A, B, C any](f2 func(B) C, f1 func(A) B) func(A) C"
description: "Compone dos funciones de derecha a izquierda. compose2(g, f)(x) = g(f(x))."
tags: [functional, composition, generic]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "functions/core/compose2.go"
---
## Ejemplo
```go
double := func(x int) int { return x * 2 }
toString := func(x int) string { return fmt.Sprintf("%d", x) }
doubleStr := Compose2(toString, double)
result := doubleStr(5) // "10"
```
## Notas
Funcion pura generica. Implementacion en devfactory/core.
+9
View File
@@ -0,0 +1,9 @@
package core
// Implementation: github.com/lucasdataproyects/devfactory/core
// Const devuelve una funcion que siempre retorna el valor dado, ignorando su argumento.
func Const[T, U any](value T) func(U) T {
// stub
return nil
}
+32
View File
@@ -0,0 +1,32 @@
---
name: const_func
kind: function
lang: go
domain: core
version: "1.0.0"
purity: pure
signature: "func Const[T, U any](value T) func(U) T"
description: "Devuelve una funcion que siempre retorna el valor dado, ignorando su argumento."
tags: [functional, generic, const]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "functions/core/const_func.go"
---
## Ejemplo
```go
always42 := Const[int, string](42)
result := always42("ignored") // 42
```
## Notas
Funcion pura generica. Implementacion en devfactory/core.
+9
View File
@@ -0,0 +1,9 @@
package core
// Implementation: github.com/lucasdataproyects/devfactory/core
// Curry2 transforma una funcion de dos argumentos en forma currificada.
func Curry2[A, B, C any](f func(A, B) C) func(A) func(B) C {
// stub
return nil
}
+34
View File
@@ -0,0 +1,34 @@
---
name: curry2
kind: function
lang: go
domain: core
version: "1.0.0"
purity: pure
signature: "func Curry2[A, B, C any](f func(A, B) C) func(A) func(B) C"
description: "Transforma una funcion de dos argumentos en forma currificada."
tags: [functional, generic, curry]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "functions/core/curry2.go"
---
## Ejemplo
```go
add := func(a, b int) int { return a + b }
curriedAdd := Curry2(add)
add5 := curriedAdd(5)
result := add5(3) // 8
```
## Notas
Funcion pura generica. Implementacion en devfactory/core.
+9
View File
@@ -0,0 +1,9 @@
package core
// Implementation: github.com/lucasdataproyects/devfactory/core
// Drop elimina los primeros n elementos de un slice y devuelve el resto.
func Drop[T any](slice []T, n int) []T {
// stub
return nil
}
+32
View File
@@ -0,0 +1,32 @@
---
name: drop
kind: function
lang: go
domain: core
version: "1.0.0"
purity: pure
signature: "func Drop[T any](slice []T, n int) []T"
description: "Elimina los primeros n elementos de un slice y devuelve el resto."
tags: [slice, functional, generic]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "functions/core/drop.go"
---
## Ejemplo
```go
result := Drop([]int{1, 2, 3, 4, 5}, 2)
// result = [3, 4, 5]
```
## Notas
Funcion pura generica. Implementacion en devfactory/core.
+9
View File
@@ -0,0 +1,9 @@
package core
// Implementation: github.com/lucasdataproyects/devfactory/core
// Find devuelve el primer elemento del slice que cumple el predicado, envuelto en Option.
func Find[T any](slice []T, predicate func(T) bool) Option[T] {
// stub
return Option[T]{}
}
+33
View File
@@ -0,0 +1,33 @@
---
name: find
kind: function
lang: go
domain: core
version: "1.0.0"
purity: pure
signature: "func Find[T any](slice []T, predicate func(T) bool) Option[T]"
description: "Devuelve el primer elemento del slice que cumple el predicado, envuelto en Option."
tags: [slice, functional, generic, search]
uses_functions: []
uses_types: [option_go_core]
returns: [option_go_core]
returns_optional: false
error_type: ""
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "functions/core/find.go"
---
## Ejemplo
```go
nums := []int{1, 2, 3, 4, 5}
result := Find(nums, func(n int) bool { return n > 3 })
// result es Some(4)
```
## Notas
Funcion pura generica. Implementacion en devfactory/core.
+9
View File
@@ -0,0 +1,9 @@
package core
// Implementation: github.com/lucasdataproyects/devfactory/core
// FindIndex devuelve el indice del primer elemento que cumple el predicado.
func FindIndex[T any](slice []T, predicate func(T) bool) Option[int] {
// stub
return Option[int]{}
}
+32
View File
@@ -0,0 +1,32 @@
---
name: find_index
kind: function
lang: go
domain: core
version: "1.0.0"
purity: pure
signature: "func FindIndex[T any](slice []T, predicate func(T) bool) Option[int]"
description: "Devuelve el indice del primer elemento que cumple el predicado, envuelto en Option."
tags: [slice, functional, generic, search]
uses_functions: []
uses_types: [option_go_core]
returns: [option_go_core]
returns_optional: false
error_type: ""
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "functions/core/find_index.go"
---
## Ejemplo
```go
idx := FindIndex([]int{10, 20, 30}, func(x int) bool { return x > 15 })
// idx = Some(1)
```
## Notas
Funcion pura generica. Implementacion en devfactory/core.
+9
View File
@@ -0,0 +1,9 @@
package core
// Implementation: github.com/lucasdataproyects/devfactory/core
// FlatMapSlice aplica una funcion que devuelve slices a cada elemento y aplana el resultado.
func FlatMapSlice[T, U any](slice []T, f func(T) []U) []U {
// stub
return nil
}
+32
View File
@@ -0,0 +1,32 @@
---
name: flat_map_slice
kind: function
lang: go
domain: core
version: "1.0.0"
purity: pure
signature: "func FlatMapSlice[T, U any](slice []T, f func(T) []U) []U"
description: "Aplica una funcion que devuelve slices a cada elemento y aplana el resultado."
tags: [slice, functional, generic, flatmap]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "functions/core/flat_map_slice.go"
---
## Ejemplo
```go
result := FlatMapSlice([]int{1, 2, 3}, func(x int) []int { return []int{x, x * 10} })
// result = [1, 10, 2, 20, 3, 30]
```
## Notas
Funcion pura generica. Implementacion en devfactory/core.
+9
View File
@@ -0,0 +1,9 @@
package core
// Implementation: github.com/lucasdataproyects/devfactory/core
// Flatten aplana un slice de slices en un unico slice.
func Flatten[T any](slices [][]T) []T {
// stub
return nil
}
+32
View File
@@ -0,0 +1,32 @@
---
name: flatten
kind: function
lang: go
domain: core
version: "1.0.0"
purity: pure
signature: "func Flatten[T any](slices [][]T) []T"
description: "Aplana un slice de slices en un unico slice."
tags: [slice, functional, generic]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "functions/core/flatten.go"
---
## Ejemplo
```go
result := Flatten([][]int{{1, 2}, {3, 4}, {5}})
// result = [1, 2, 3, 4, 5]
```
## Notas
Funcion pura generica. Implementacion en devfactory/core.
+9
View File
@@ -0,0 +1,9 @@
package core
// Implementation: github.com/lucasdataproyects/devfactory/core
// Flip intercambia el orden de los argumentos de una funcion de dos parametros.
func Flip[A, B, C any](f func(A, B) C) func(B, A) C {
// stub
return nil
}
+33
View File
@@ -0,0 +1,33 @@
---
name: flip
kind: function
lang: go
domain: core
version: "1.0.0"
purity: pure
signature: "func Flip[A, B, C any](f func(A, B) C) func(B, A) C"
description: "Intercambia el orden de los argumentos de una funcion de dos parametros."
tags: [functional, generic]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "functions/core/flip.go"
---
## Ejemplo
```go
sub := func(a, b int) int { return a - b }
flipped := Flip(sub)
result := flipped(3, 10) // 7 (10 - 3)
```
## Notas
Funcion pura generica. Implementacion en devfactory/core.
+9
View File
@@ -0,0 +1,9 @@
package core
// Implementation: github.com/lucasdataproyects/devfactory/core
// GroupBy agrupa elementos de un slice por clave generada con una funcion.
func GroupBy[T any, K comparable](slice []T, keyFn func(T) K) map[K][]T {
// stub
return nil
}
+32
View File
@@ -0,0 +1,32 @@
---
name: group_by
kind: function
lang: go
domain: core
version: "1.0.0"
purity: pure
signature: "func GroupBy[T any, K comparable](slice []T, keyFn func(T) K) map[K][]T"
description: "Agrupa elementos de un slice por clave generada con una funcion."
tags: [slice, functional, generic, grouping]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "functions/core/group_by.go"
---
## Ejemplo
```go
groups := GroupBy([]string{"go", "git", "python"}, func(s string) byte { return s[0] })
// groups = map[byte][]string{'g': {"go", "git"}, 'p': {"python"}}
```
## Notas
Funcion pura generica. Implementacion en devfactory/core.
+10
View File
@@ -0,0 +1,10 @@
package core
// Implementation: github.com/lucasdataproyects/devfactory/core
// Identity devuelve el valor recibido sin modificarlo.
func Identity[T any](x T) T {
// stub
var zero T
return zero
}
+32
View File
@@ -0,0 +1,32 @@
---
name: identity
kind: function
lang: go
domain: core
version: "1.0.0"
purity: pure
signature: "func Identity[T any](x T) T"
description: "Devuelve el valor recibido sin modificarlo. Elemento neutro de la composicion."
tags: [functional, generic, identity]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "functions/core/identity.go"
---
## Ejemplo
```go
x := Identity(42) // 42
s := Identity("abc") // "abc"
```
## Notas
Funcion pura generica. Implementacion en devfactory/core.
+9
View File
@@ -0,0 +1,9 @@
package core
// Implementation: github.com/lucasdataproyects/devfactory/core
// Partial2 aplica parcialmente el primer argumento de una funcion de dos parametros.
func Partial2[A, B, C any](f func(A, B) C, a A) func(B) C {
// stub
return nil
}
+33
View File
@@ -0,0 +1,33 @@
---
name: partial2
kind: function
lang: go
domain: core
version: "1.0.0"
purity: pure
signature: "func Partial2[A, B, C any](f func(A, B) C, a A) func(B) C"
description: "Aplica parcialmente el primer argumento de una funcion de dos parametros."
tags: [functional, generic, partial]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "functions/core/partial2.go"
---
## Ejemplo
```go
mul := func(a, b int) int { return a * b }
double := Partial2(mul, 2)
result := double(5) // 10
```
## Notas
Funcion pura generica. Implementacion en devfactory/core.
+9
View File
@@ -0,0 +1,9 @@
package core
// Implementation: github.com/lucasdataproyects/devfactory/core
// Pipe2 compone dos funciones de izquierda a derecha.
func Pipe2[A, B, C any](f1 func(A) B, f2 func(B) C) func(A) C {
// stub
return nil
}
+34
View File
@@ -0,0 +1,34 @@
---
name: pipe2
kind: function
lang: go
domain: core
version: "1.0.0"
purity: pure
signature: "func Pipe2[A, B, C any](f1 func(A) B, f2 func(B) C) func(A) C"
description: "Compone dos funciones de izquierda a derecha. pipe2(f, g)(x) = g(f(x))."
tags: [functional, composition, generic, pipe]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "functions/core/pipe2.go"
---
## Ejemplo
```go
double := func(x int) int { return x * 2 }
toString := func(x int) string { return fmt.Sprintf("%d", x) }
doubleStr := Pipe2(double, toString)
result := doubleStr(5) // "10"
```
## Notas
Funcion pura generica. Implementacion en devfactory/core.
+9
View File
@@ -0,0 +1,9 @@
package core
// Implementation: github.com/lucasdataproyects/devfactory/core
// Pipe3 compone tres funciones de izquierda a derecha.
func Pipe3[A, B, C, D any](f1 func(A) B, f2 func(B) C, f3 func(C) D) func(A) D {
// stub
return nil
}
+35
View File
@@ -0,0 +1,35 @@
---
name: pipe3
kind: function
lang: go
domain: core
version: "1.0.0"
purity: pure
signature: "func Pipe3[A, B, C, D any](f1 func(A) B, f2 func(B) C, f3 func(C) D) func(A) D"
description: "Compone tres funciones de izquierda a derecha."
tags: [functional, composition, generic, pipe]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "functions/core/pipe3.go"
---
## Ejemplo
```go
add1 := func(x int) int { return x + 1 }
double := func(x int) int { return x * 2 }
toString := func(x int) string { return fmt.Sprintf("%d", x) }
pipeline := Pipe3(add1, double, toString)
result := pipeline(3) // "8"
```
## Notas
Funcion pura generica. Implementacion en devfactory/core.
+9
View File
@@ -0,0 +1,9 @@
package core
// Implementation: github.com/lucasdataproyects/devfactory/core
// Reduce reduce un slice a un unico valor aplicando una funcion acumuladora.
func Reduce[T, U any](slice []T, initial U, f func(U, T) U) U {
// stub
return initial
}
+32
View File
@@ -0,0 +1,32 @@
---
name: reduce
kind: function
lang: go
domain: core
version: "1.0.0"
purity: pure
signature: "func Reduce[T, U any](slice []T, initial U, f func(U, T) U) U"
description: "Reduce un slice a un unico valor aplicando una funcion acumuladora de izquierda a derecha."
tags: [slice, functional, generic, fold]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "functions/core/reduce.go"
---
## Ejemplo
```go
sum := Reduce([]int{1, 2, 3, 4}, 0, func(acc, x int) int { return acc + x })
// sum = 10
```
## Notas
Funcion pura generica. Implementacion en devfactory/core.
+9
View File
@@ -0,0 +1,9 @@
package core
// Implementation: github.com/lucasdataproyects/devfactory/core
// Take devuelve los primeros n elementos de un slice.
func Take[T any](slice []T, n int) []T {
// stub
return nil
}
+32
View File
@@ -0,0 +1,32 @@
---
name: take
kind: function
lang: go
domain: core
version: "1.0.0"
purity: pure
signature: "func Take[T any](slice []T, n int) []T"
description: "Devuelve los primeros n elementos de un slice."
tags: [slice, functional, generic]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "functions/core/take.go"
---
## Ejemplo
```go
result := Take([]int{1, 2, 3, 4, 5}, 3)
// result = [1, 2, 3]
```
## Notas
Funcion pura generica. Implementacion en devfactory/core.
+9
View File
@@ -0,0 +1,9 @@
package core
// Implementation: github.com/lucasdataproyects/devfactory/core
// Uncurry2 transforma una funcion currificada en una funcion normal de dos argumentos.
func Uncurry2[A, B, C any](f func(A) func(B) C) func(A, B) C {
// stub
return nil
}
+35
View File
@@ -0,0 +1,35 @@
---
name: uncurry2
kind: function
lang: go
domain: core
version: "1.0.0"
purity: pure
signature: "func Uncurry2[A, B, C any](f func(A) func(B) C) func(A, B) C"
description: "Transforma una funcion currificada en una funcion normal de dos argumentos."
tags: [functional, generic, curry]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "functions/core/uncurry2.go"
---
## Ejemplo
```go
curriedAdd := func(a int) func(int) int {
return func(b int) int { return a + b }
}
add := Uncurry2(curriedAdd)
result := add(3, 5) // 8
```
## Notas
Funcion pura generica. Implementacion en devfactory/core.
+9
View File
@@ -0,0 +1,9 @@
package core
// Implementation: github.com/lucasdataproyects/devfactory/core
// Unique devuelve un slice con elementos unicos preservando el orden original.
func Unique[T comparable](slice []T) []T {
// stub
return nil
}
+32
View File
@@ -0,0 +1,32 @@
---
name: unique
kind: function
lang: go
domain: core
version: "1.0.0"
purity: pure
signature: "func Unique[T comparable](slice []T) []T"
description: "Devuelve un slice con elementos unicos preservando el orden original."
tags: [slice, functional, generic, dedup]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "functions/core/unique.go"
---
## Ejemplo
```go
result := Unique([]int{1, 2, 2, 3, 1, 4})
// result = [1, 2, 3, 4]
```
## Notas
Funcion pura generica. Implementacion en devfactory/core.
+9
View File
@@ -0,0 +1,9 @@
package core
// Implementation: github.com/lucasdataproyects/devfactory/core
// Zip combina dos slices en un slice de pares elemento a elemento.
func Zip[T, U any](a []T, b []U) []Pair[T, U] {
// stub
return nil
}
+32
View File
@@ -0,0 +1,32 @@
---
name: zip
kind: function
lang: go
domain: core
version: "1.0.0"
purity: pure
signature: "func Zip[T, U any](a []T, b []U) []Pair[T, U]"
description: "Combina dos slices en un slice de pares elemento a elemento."
tags: [slice, functional, generic, pair]
uses_functions: []
uses_types: [pair_go_core]
returns: [pair_go_core]
returns_optional: false
error_type: ""
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "functions/core/zip.go"
---
## Ejemplo
```go
pairs := Zip([]string{"a", "b"}, []int{1, 2})
// pairs = [{a 1}, {b 2}]
```
## Notas
Funcion pura generica. Implementacion en devfactory/core.