Skip to content

once

once<A>(f): () => A

Defined in: Composition/fn.ts:92

Creates a function that executes at most once. Subsequent calls return the cached result from the first execution.

A

() => A

(): A

A

let count = 0;
const initOnce = once(() => { count++; return "initialized"; });

initOnce(); // "initialized", count === 1
initOnce(); // "initialized", count === 1 (not called again)