mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-08 17:03:53 +00:00
13 lines
261 B
TypeScript
13 lines
261 B
TypeScript
/**
|
|
* Allows lazy evaluation and caching of a functions result
|
|
*/
|
|
export function lazyEvaluate<T>(fn: () => T): () => T {
|
|
let result: T | undefined;
|
|
return function () {
|
|
if (result === undefined) {
|
|
result = fn();
|
|
}
|
|
return result;
|
|
};
|
|
}
|