Funx Documentation
Funx Documentation
Version: 1.3.0
Package: funx — composable async/sync function decorators for Dart.
Funx wraps ordinary functions in small, chainable, reusable building blocks. Each block adds a single concern — timing, concurrency, reliability, caching, observability, and more — without rewriting the function itself.
| |
What is a decorator?
A decorator is an extension method on Func, Func1, or Func2 (or a standalone class) that wraps the original function and changes how it executes. Decorators are composable: you can chain them to combine behaviors.
Wrapper types
| Wrapper | Signature | Decorators? |
|---|---|---|
Func<R> | Future<R> call() | Full async decorator set |
Func1<T, R> | Future<R> call(T arg) | Full async decorator set |
Func2<T1, T2, R> | Future<R> call(T1 arg1, T2 arg2) | Full async decorator set |
FuncSync<R> | R call() | Scheduling decorators only |
FuncSync1<T, R> | R call(T arg) | None |
FuncSync2<T1, T2, R> | R call(T1 arg1, T2 arg2) | None |
FuncSync* wrappers exist for API symmetry; most decorators are async-only because they rely on Future, Timer, or concurrent execution.
Category map
| Category | Mechanisms | File |
|---|---|---|
| Core | Func, Func1, Func2, FuncSync*, AsyncFunction*, SyncFunction* | core.md |
| Timing | debounce, throttle, delay, timeout, defer, idleCallback | timing.md |
| Concurrency | lock, readLock/writeLock, semaphore, bulkhead, barrier, countdownLatch, monitor, queue | concurrency.md |
| Scheduling | schedule, scheduleRecurring, scheduleCustom, backpressure | scheduling.md |
| Reliability | retry, backoff, circuitBreaker, fallback, recover | reliability.md |
| Error Handling | catchError, defaultValue | error_handling.md |
| Performance | lazy, warmUp, batch, cacheAside, priorityQueue, rateLimit, memoize, deduplicate, share, compress, once | performance.md |
| Observability | tap, monitorObservability, audit | observability.md |
| State | snapshot | state.md |
| Validation | validate, guard | validation.md |
| Control Flow | when, repeat, switch | control_flow.md |
| Transformation | transform, merge, proxy | transformation.md |
| Orchestration | race, all, saga | orchestration.md |
Quick start
Add to
pubspec.yaml:1 2dependencies: funx: ^1.3.0Import and wrap a function:
1 2 3 4 5 6 7 8 9 10final fetchUser = Func1<String, User>( (id) async => (await api.getUser(id)) as User, ).timeout(Duration(seconds: 5)) .retry(maxAttempts: 3) .memoize(); void main() async { final user = await fetchUser('123'); print(user); }Call it like any async function:
1 2 3 4 5 6 7 8final fetchUser = Func1<String, User>( (id) async => (await api.getUser(id)) as User, ); void main() async { final user = await fetchUser('123'); print(user); }
How to read the category docs
Each mechanism is documented with the same structure:
- What it is — short conceptual overview.
- When to use it — typical use cases.
- Async / sync support — which wrappers support the decorator.
- API reference — public classes, enums, and key members with defaults.
- Examples — minimal and real-world snippets.
- Best practices — recommended usage.
- Common pitfalls — exceptions, edge cases, and gotchas.
Version note
This documentation targets funx v1.3.0. v1.3.0 refactored shared logic into internal engine files (_timing_engine.dart, _reliability_engines.dart, _observability_engines.dart, _concurrency_engines.dart) without changing the public API.
Resources
- funx on pub.dev — install the package.
- API reference — generated Dart API docs.
- funx library docs — core library entry point.
- GitHub repository — source code, issues, and PRs.
- Maksymilian Jakcowski on GitHub — author profile.
Contributing
Found an inaccuracy? The source of truth is lib/funx.dart and the files under lib/src/. Open an issue or PR with a reference to the relevant source file.