fn
once
v0.0.10testedWraps a function so it runs at most once; subsequent calls return the first result
Example
ts
const init = once(() => Math.random());
init(); // 0.42
init(); // 0.42 (cached)
init.clear();
init(); // 0.91 (runs again)Signature
ts
export function once<T extends AnyFunction>(fn: T): OnceFunction<T>{ ... }Type Parameters
Textends AnyFunctionParameters
| Parameter | Type | Description |
|---|---|---|
fn | T | The function to guard |
Returns
OnceFunction<T>The guarded function with a `clear()` method to reset it