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
aiwonderland-1.0.0.tar.gz
(9.5 kB
view details)
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-1.0.0.tar.gz.
File metadata
- Download URL: aiwonderland-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 |
71447d7902c9fb8d1f34a489d3bb2f7a429939b9b8ccd6b4d8f31ac03f711501
|
|
| MD5 |
b75191790021dc64bd2a8f06a01dd23d
|
|
| BLAKE2b-256 |
6ec47e8fd928763be04c49695c525956ea34bba6b9dcfcfee1d3dd2194f55150
|
File details
Details for the file aiwonderland-1.0.0-py3-none-any.whl.
File metadata
- Download URL: aiwonderland-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.9 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 |
dd1aa59f29a6796edccd56399498e952a4f86199a8e9e8867123ce6199c73c49
|
|
| MD5 |
6592cf21d1e23dcff3abf3047a1cf86c
|
|
| BLAKE2b-256 |
d4836bb4977ec5f8fe4630a8333bfa485a8e1bb7e82247306ada3bb3e2da4fa3
|