Skip to main content

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_functools-1.0.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiwonderland_functools-1.0.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

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

Hashes for aiwonderland_functools-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1ab2207e07d9059b7b717705843163bdb24e828071cd44a3af76604252f528b3
MD5 1343403eb2358df34cb181c20b5fc071
BLAKE2b-256 dbf3ed7f672ff5f9cfc2d0dadb3df617f70ed05d2494deae42bdb7933ae83eb3

See more details on using hashes here.

File details

Details for the file aiwonderland_functools-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aiwonderland_functools-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8749bcb917f830f25f4b32f5ae1d2ad48105d57626dc615b5fb63db7095e797a
MD5 90fb990b2cf0ecd019f253f46805a924
BLAKE2b-256 c6191f3cacca8d6532224e8a961dc1f0d915689265b817e3d9612d74a448ba83

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page