API reference › @evolu/common › Function › Lazy
type Lazy<T> = () => T;
Defined in: packages/common/src/Function.ts:140
A function that takes no arguments and returns a value of type T. Also known as a thunk.
Useful for:
- Providing default callbacks (see lazyVoid, lazyTrue, etc.)
- Delaying expensive operations until actually needed
- Deferring side effects so the callee controls when they run
Example
// Default callback
const notify = (onDone: Lazy<void> = lazyVoid) => {
onDone();
};
// Delay computation
const getData: Lazy<Data> = () => compute();
const data = getData();
// Defer side effects
const schedule = (job: Lazy<void>) => {
queueMicrotask(job);
};
schedule(() => logMetric("loaded"));