feat: funciones Python para core, cybersecurity, datascience y finance
Agrega funciones Python reutilizables organizadas por dominio: - core: composicion funcional (pipe, compose, map, filter, reduce, etc.) - cybersecurity: analisis de amenazas y puertos - datascience: estadisticas y deteccion de outliers - finance: indicadores tecnicos y analisis financiero
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
"""Core functional programming utilities."""
|
||||
|
||||
from .core import (
|
||||
all_of,
|
||||
any_of,
|
||||
chunk,
|
||||
compose,
|
||||
drop,
|
||||
filter_list,
|
||||
find,
|
||||
find_index,
|
||||
flat_map,
|
||||
flatten,
|
||||
group_by,
|
||||
map_list,
|
||||
partition,
|
||||
pipe,
|
||||
reduce_list,
|
||||
take,
|
||||
unique,
|
||||
zip_with,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"all_of",
|
||||
"any_of",
|
||||
"chunk",
|
||||
"compose",
|
||||
"drop",
|
||||
"filter_list",
|
||||
"find",
|
||||
"find_index",
|
||||
"flat_map",
|
||||
"flatten",
|
||||
"group_by",
|
||||
"map_list",
|
||||
"partition",
|
||||
"pipe",
|
||||
"reduce_list",
|
||||
"take",
|
||||
"unique",
|
||||
"zip_with",
|
||||
]
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: all_of
|
||||
kind: function
|
||||
lang: py
|
||||
domain: core
|
||||
version: "1.0.0"
|
||||
purity: pure
|
||||
signature: "def all_of(xs: list, pred: callable) -> bool"
|
||||
description: "Retorna True si todos los elementos de la lista cumplen el predicado."
|
||||
tags: [list, functional, predicate, all, python]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: ""
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "python/functions/core/core.py"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```python
|
||||
result = all_of([2, 4, 6], lambda n: n % 2 == 0)
|
||||
# True
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Funcion pura. Retorna True para lista vacia (vacuamente verdadero). Cortocircuita al primer False.
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: any_of
|
||||
kind: function
|
||||
lang: py
|
||||
domain: core
|
||||
version: "1.0.0"
|
||||
purity: pure
|
||||
signature: "def any_of(xs: list, pred: callable) -> bool"
|
||||
description: "Retorna True si al menos un elemento de la lista cumple el predicado."
|
||||
tags: [list, functional, predicate, any, python]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: ""
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "python/functions/core/core.py"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```python
|
||||
result = any_of([1, 3, 5, 4], lambda n: n % 2 == 0)
|
||||
# True
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Funcion pura. Retorna False para lista vacia. Cortocircuita al primer True.
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: chunk
|
||||
kind: function
|
||||
lang: py
|
||||
domain: core
|
||||
version: "1.0.0"
|
||||
purity: pure
|
||||
signature: "def chunk(xs: list, size: int) -> list"
|
||||
description: "Divide una lista en sublistas de tamanio fijo. El ultimo chunk puede ser menor."
|
||||
tags: [list, functional, chunk, partition, python]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: ""
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "python/functions/core/core.py"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```python
|
||||
result = chunk([1, 2, 3, 4, 5], 2)
|
||||
# [[1, 2], [3, 4], [5]]
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Funcion pura. Si size <= 0 retorna lista vacia.
|
||||
@@ -0,0 +1,33 @@
|
||||
---
|
||||
name: compose
|
||||
kind: function
|
||||
lang: py
|
||||
domain: core
|
||||
version: "1.0.0"
|
||||
purity: pure
|
||||
signature: "def compose(*fns) -> callable"
|
||||
description: "Compone funciones de derecha a izquierda. compose(f, g)(x) == f(g(x))."
|
||||
tags: [functional, compose, composition, python]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: ""
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "python/functions/core/core.py"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```python
|
||||
double_then_str = compose(str, lambda n: n * 2)
|
||||
result = double_then_str(5)
|
||||
# "10"
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Funcion pura. Composicion matematica: la ultima funcion se aplica primero. Inverso de pipe.
|
||||
@@ -0,0 +1,135 @@
|
||||
"""Core functional programming utilities — pure functions for list/collection operations."""
|
||||
|
||||
from functools import reduce as _reduce
|
||||
from typing import Any, Callable, Dict, List, Tuple
|
||||
|
||||
|
||||
def filter_list(xs: list, pred: Callable) -> list:
|
||||
"""Filter list by predicate. Does not mutate the original."""
|
||||
return [x for x in xs if pred(x)]
|
||||
|
||||
|
||||
def map_list(xs: list, fn: Callable) -> list:
|
||||
"""Map function over list. Does not mutate the original."""
|
||||
return [fn(x) for x in xs]
|
||||
|
||||
|
||||
def reduce_list(xs: list, initial: Any, fn: Callable) -> Any:
|
||||
"""Reduce list with accumulator. fn(acc, x) -> acc."""
|
||||
return _reduce(fn, xs, initial)
|
||||
|
||||
|
||||
def flat_map(xs: list, fn: Callable) -> list:
|
||||
"""Map function over list then flatten one level."""
|
||||
result = []
|
||||
for x in xs:
|
||||
result.extend(fn(x))
|
||||
return result
|
||||
|
||||
|
||||
def flatten(xss: list) -> list:
|
||||
"""Flatten a list of lists one level."""
|
||||
result = []
|
||||
for xs in xss:
|
||||
result.extend(xs)
|
||||
return result
|
||||
|
||||
|
||||
def chunk(xs: list, size: int) -> list:
|
||||
"""Split list into chunks of given size. Last chunk may be smaller."""
|
||||
if size <= 0:
|
||||
return []
|
||||
return [xs[i : i + size] for i in range(0, len(xs), size)]
|
||||
|
||||
|
||||
def take(xs: list, n: int) -> list:
|
||||
"""Take first n elements from list."""
|
||||
return xs[:n]
|
||||
|
||||
|
||||
def drop(xs: list, n: int) -> list:
|
||||
"""Drop first n elements from list."""
|
||||
return xs[n:]
|
||||
|
||||
|
||||
def unique(xs: list) -> list:
|
||||
"""Remove duplicates preserving order. Uses identity for hashable elements."""
|
||||
seen = set()
|
||||
result = []
|
||||
for x in xs:
|
||||
if x not in seen:
|
||||
seen.add(x)
|
||||
result.append(x)
|
||||
return result
|
||||
|
||||
|
||||
def group_by(xs: list, key_fn: Callable) -> Dict:
|
||||
"""Group elements by key function. Returns dict of key -> list."""
|
||||
groups: Dict = {}
|
||||
for x in xs:
|
||||
k = key_fn(x)
|
||||
if k not in groups:
|
||||
groups[k] = []
|
||||
groups[k].append(x)
|
||||
return groups
|
||||
|
||||
|
||||
def partition(xs: list, pred: Callable) -> Tuple[list, list]:
|
||||
"""Split list into (matches, non_matches) based on predicate."""
|
||||
matches = []
|
||||
non_matches = []
|
||||
for x in xs:
|
||||
if pred(x):
|
||||
matches.append(x)
|
||||
else:
|
||||
non_matches.append(x)
|
||||
return (matches, non_matches)
|
||||
|
||||
|
||||
def find(xs: list, pred: Callable) -> Any:
|
||||
"""Find first element matching predicate. Returns None if not found."""
|
||||
for x in xs:
|
||||
if pred(x):
|
||||
return x
|
||||
return None
|
||||
|
||||
|
||||
def find_index(xs: list, pred: Callable) -> int:
|
||||
"""Find index of first element matching predicate. Returns -1 if not found."""
|
||||
for i, x in enumerate(xs):
|
||||
if pred(x):
|
||||
return i
|
||||
return -1
|
||||
|
||||
|
||||
def zip_with(xs: list, ys: list, fn: Callable) -> list:
|
||||
"""Zip two lists with a combining function. Stops at shorter list."""
|
||||
return [fn(x, y) for x, y in zip(xs, ys)]
|
||||
|
||||
|
||||
def all_of(xs: list, pred: Callable) -> bool:
|
||||
"""Return True if all elements match predicate."""
|
||||
return all(pred(x) for x in xs)
|
||||
|
||||
|
||||
def any_of(xs: list, pred: Callable) -> bool:
|
||||
"""Return True if any element matches predicate."""
|
||||
return any(pred(x) for x in xs)
|
||||
|
||||
|
||||
def pipe(value: Any, *fns: Callable) -> Any:
|
||||
"""Pipe a value through a sequence of functions left-to-right."""
|
||||
result = value
|
||||
for fn in fns:
|
||||
result = fn(result)
|
||||
return result
|
||||
|
||||
|
||||
def compose(*fns: Callable) -> Callable:
|
||||
"""Compose functions right-to-left. compose(f, g)(x) == f(g(x))."""
|
||||
def composed(x: Any) -> Any:
|
||||
result = x
|
||||
for fn in reversed(fns):
|
||||
result = fn(result)
|
||||
return result
|
||||
return composed
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: drop
|
||||
kind: function
|
||||
lang: py
|
||||
domain: core
|
||||
version: "1.0.0"
|
||||
purity: pure
|
||||
signature: "def drop(xs: list, n: int) -> list"
|
||||
description: "Descarta los primeros n elementos de una lista."
|
||||
tags: [list, functional, drop, slice, python]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: ""
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "python/functions/core/core.py"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```python
|
||||
result = drop([1, 2, 3, 4, 5], 2)
|
||||
# [3, 4, 5]
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Funcion pura. Si n > len(xs), retorna lista vacia. No muta la original.
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: filter_list
|
||||
kind: function
|
||||
lang: py
|
||||
domain: core
|
||||
version: "1.0.0"
|
||||
purity: pure
|
||||
signature: "def filter_list(xs: list, pred: callable) -> list"
|
||||
description: "Filtra una lista aplicando un predicado sin mutar la original."
|
||||
tags: [list, functional, filter, python]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: ""
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "python/functions/core/core.py"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```python
|
||||
evens = filter_list([1, 2, 3, 4], lambda n: n % 2 == 0)
|
||||
# [2, 4]
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Funcion pura. No muta la lista original. Equivalente a `[x for x in xs if pred(x)]`.
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: find
|
||||
kind: function
|
||||
lang: py
|
||||
domain: core
|
||||
version: "1.0.0"
|
||||
purity: pure
|
||||
signature: "def find(xs: list, pred: callable)"
|
||||
description: "Encuentra el primer elemento que cumple el predicado. Retorna None si no hay coincidencia."
|
||||
tags: [list, functional, find, search, python]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: ""
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "python/functions/core/core.py"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```python
|
||||
result = find([1, 2, 3, 4], lambda n: n > 2)
|
||||
# 3
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Funcion pura. Retorna None si ningun elemento cumple el predicado. Cortocircuita al primer match.
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: find_index
|
||||
kind: function
|
||||
lang: py
|
||||
domain: core
|
||||
version: "1.0.0"
|
||||
purity: pure
|
||||
signature: "def find_index(xs: list, pred: callable) -> int"
|
||||
description: "Encuentra el indice del primer elemento que cumple el predicado. Retorna -1 si no hay coincidencia."
|
||||
tags: [list, functional, find, index, search, python]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: ""
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "python/functions/core/core.py"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```python
|
||||
idx = find_index([10, 20, 30, 40], lambda n: n > 25)
|
||||
# 2
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Funcion pura. Retorna -1 si ningun elemento cumple el predicado.
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: flat_map
|
||||
kind: function
|
||||
lang: py
|
||||
domain: core
|
||||
version: "1.0.0"
|
||||
purity: pure
|
||||
signature: "def flat_map(xs: list, fn: callable) -> list"
|
||||
description: "Aplica una funcion que retorna listas a cada elemento y aplana el resultado un nivel."
|
||||
tags: [list, functional, flatmap, python]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: ""
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "python/functions/core/core.py"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```python
|
||||
result = flat_map([1, 2, 3], lambda n: [n, n * 10])
|
||||
# [1, 10, 2, 20, 3, 30]
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Funcion pura. Equivalente a flatten(map_list(xs, fn)). Solo aplana un nivel.
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: flatten
|
||||
kind: function
|
||||
lang: py
|
||||
domain: core
|
||||
version: "1.0.0"
|
||||
purity: pure
|
||||
signature: "def flatten(xss: list) -> list"
|
||||
description: "Aplana una lista de listas un nivel, concatenando las sublistas."
|
||||
tags: [list, functional, flatten, python]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: ""
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "python/functions/core/core.py"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```python
|
||||
result = flatten([[1, 2], [3], [4, 5]])
|
||||
# [1, 2, 3, 4, 5]
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Funcion pura. Solo aplana un nivel de anidamiento.
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: group_by
|
||||
kind: function
|
||||
lang: py
|
||||
domain: core
|
||||
version: "1.0.0"
|
||||
purity: pure
|
||||
signature: "def group_by(xs: list, key_fn: callable) -> dict"
|
||||
description: "Agrupa elementos de una lista por una funcion clave. Retorna dict de clave a lista."
|
||||
tags: [list, functional, group, classify, python]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: ""
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "python/functions/core/core.py"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```python
|
||||
result = group_by(["hi", "hey", "bye"], lambda s: s[0])
|
||||
# {"h": ["hi", "hey"], "b": ["bye"]}
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Funcion pura. El orden de los elementos dentro de cada grupo se preserva.
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: map_list
|
||||
kind: function
|
||||
lang: py
|
||||
domain: core
|
||||
version: "1.0.0"
|
||||
purity: pure
|
||||
signature: "def map_list(xs: list, fn: callable) -> list"
|
||||
description: "Aplica una funcion a cada elemento de una lista, retornando una nueva lista."
|
||||
tags: [list, functional, map, python]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: ""
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "python/functions/core/core.py"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```python
|
||||
doubled = map_list([1, 2, 3], lambda n: n * 2)
|
||||
# [2, 4, 6]
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Funcion pura. No muta la lista original. Equivalente a `[fn(x) for x in xs]`.
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: partition
|
||||
kind: function
|
||||
lang: py
|
||||
domain: core
|
||||
version: "1.0.0"
|
||||
purity: pure
|
||||
signature: "def partition(xs: list, pred: callable) -> tuple"
|
||||
description: "Divide una lista en dos: (elementos que cumplen el predicado, elementos que no)."
|
||||
tags: [list, functional, partition, split, python]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: ""
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "python/functions/core/core.py"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```python
|
||||
evens, odds = partition([1, 2, 3, 4, 5], lambda n: n % 2 == 0)
|
||||
# evens = [2, 4], odds = [1, 3, 5]
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Funcion pura. Retorna tupla de dos listas: (matches, non_matches).
|
||||
@@ -0,0 +1,36 @@
|
||||
---
|
||||
name: pipe
|
||||
kind: function
|
||||
lang: py
|
||||
domain: core
|
||||
version: "1.0.0"
|
||||
purity: pure
|
||||
signature: "def pipe(value, *fns)"
|
||||
description: "Pasa un valor a traves de una secuencia de funciones de izquierda a derecha."
|
||||
tags: [functional, pipe, composition, python]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: ""
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "python/functions/core/core.py"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```python
|
||||
result = pipe(
|
||||
[1, 2, 3, 4, 5],
|
||||
lambda xs: filter_list(xs, lambda n: n > 2),
|
||||
lambda xs: map_list(xs, lambda n: n * 10),
|
||||
)
|
||||
# [30, 40, 50]
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Funcion pura. Ejecuta las funciones en orden de izquierda a derecha: f1(value), luego f2(result), etc.
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: reduce_list
|
||||
kind: function
|
||||
lang: py
|
||||
domain: core
|
||||
version: "1.0.0"
|
||||
purity: pure
|
||||
signature: "def reduce_list(xs: list, initial, fn: callable)"
|
||||
description: "Reduce una lista con un acumulador y una funcion binaria fn(acc, x)."
|
||||
tags: [list, functional, reduce, fold, python]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: ""
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "python/functions/core/core.py"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```python
|
||||
total = reduce_list([1, 2, 3, 4], 0, lambda acc, x: acc + x)
|
||||
# 10
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Funcion pura. Usa functools.reduce internamente. El valor inicial es obligatorio para evitar errores con listas vacias.
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: take
|
||||
kind: function
|
||||
lang: py
|
||||
domain: core
|
||||
version: "1.0.0"
|
||||
purity: pure
|
||||
signature: "def take(xs: list, n: int) -> list"
|
||||
description: "Toma los primeros n elementos de una lista."
|
||||
tags: [list, functional, take, slice, python]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: ""
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "python/functions/core/core.py"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```python
|
||||
result = take([1, 2, 3, 4, 5], 3)
|
||||
# [1, 2, 3]
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Funcion pura. Si n > len(xs), retorna toda la lista. No muta la original.
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: unique
|
||||
kind: function
|
||||
lang: py
|
||||
domain: core
|
||||
version: "1.0.0"
|
||||
purity: pure
|
||||
signature: "def unique(xs: list) -> list"
|
||||
description: "Elimina duplicados de una lista preservando el orden de aparicion."
|
||||
tags: [list, functional, unique, deduplicate, python]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: ""
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "python/functions/core/core.py"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```python
|
||||
result = unique([1, 2, 2, 3, 1, 4])
|
||||
# [1, 2, 3, 4]
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Funcion pura. Preserva el orden de la primera aparicion. Requiere elementos hashables.
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: zip_with
|
||||
kind: function
|
||||
lang: py
|
||||
domain: core
|
||||
version: "1.0.0"
|
||||
purity: pure
|
||||
signature: "def zip_with(xs: list, ys: list, fn: callable) -> list"
|
||||
description: "Combina dos listas elemento a elemento con una funcion. Se detiene en la mas corta."
|
||||
tags: [list, functional, zip, combine, python]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: ""
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "python/functions/core/core.py"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```python
|
||||
result = zip_with([1, 2, 3], [10, 20, 30], lambda a, b: a + b)
|
||||
# [11, 22, 33]
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Funcion pura. Se detiene en la lista mas corta, como zip() de Python.
|
||||
Reference in New Issue
Block a user