@adviser/cement - v0.0.0
    Preparing search index...

    Function Lazy

    • Creates a lazy-evaluated version of a function that executes only once and caches the result.

      The returned function will execute the original function on first call and return the cached result for all subsequent calls, regardless of arguments. This is useful for expensive computations or resource initialization.

      Type Parameters

      • Args extends readonly unknown[]

        The argument types of the function

      • Return

        The return type of the function

      Parameters

      Returns (...args: Args) => Return

      A wrapped function that executes once and caches the result

      const getConfig = Lazy(() => {
      console.log('Loading config...');
      return { apiKey: 'secret' };
      });

      getConfig(); // Logs "Loading config..." and returns config
      getConfig(); // Returns cached config without logging