aiwonderland.functools
My main Python functools toolset.
Additional functools in the spirit of the standard library's functools.
pip install -e . to install from a checkout. Python 3.10+. No
runtime dependencies.
aiwonderland.functools
| Decorator / factory | What it does |
|---|---|
once(func) |
run func at most once, cache the result |
silent(default) |
catch Exception, return default |
pipe(*funcs) |
left-to-right composition |
pass_param(func, validator, fb) |
short-circuit on a sentinel first argument |
memoize(func) |
cache results keyed by arguments |
tap(side_effect=print) |
log calls; return value unchanged |
print_yielded(func) |
print every value a generator yields |
run_sync(coro_func) |
call an async def synchronously |
See each callable's docstring for parameters, return type, and examples.
from aiwonderland.functools import memoize, pipe, run_sync
@memoize
def fib(n):
return n if n < 2 else fib(n - 1) + fib(n - 2)
@run_sync
async def fetch_status():
return "ok"
print(fib(50), pipe(lambda x: x * 2, lambda x: x + 1)(3), fetch_status())
License
MIT. See LICENSE.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aiwonderland_functools-1.0.0.tar.gz.
File metadata
- Download URL: aiwonderland_functools-1.0.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ab2207e07d9059b7b717705843163bdb24e828071cd44a3af76604252f528b3
|
|
| MD5 |
1343403eb2358df34cb181c20b5fc071
|
|
| BLAKE2b-256 |
dbf3ed7f672ff5f9cfc2d0dadb3df617f70ed05d2494deae42bdb7933ae83eb3
|
File details
Details for the file aiwonderland_functools-1.0.0-py3-none-any.whl.
File metadata
- Download URL: aiwonderland_functools-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8749bcb917f830f25f4b32f5ae1d2ad48105d57626dc615b5fb63db7095e797a
|
|
| MD5 |
90fb990b2cf0ecd019f253f46805a924
|
|
| BLAKE2b-256 |
c6191f3cacca8d6532224e8a961dc1f0d915689265b817e3d9612d74a448ba83
|