Utility Function for One-Time Callable Memoization
Hi! Do we have a utility function that wraps a function without arguments and makes it callable only once, effectively memoizing its result forever. Here's a basic implementation to make you understand what I need:
function once<T>(fn: () => T): () => T { let hasRun = false; let result: T; return () => { if (!hasRun) { result = fn(); hasRun = true; } return result; };}
function once<T>(fn: () => T): () => T { let hasRun = false; let result: T; return () => { if (!hasRun) { result = fn(); hasRun = true; } return result; };}