@blinkk/degu
    Preparing search index...

    Function memoizeSimple

    • Memoizes a function with just a one time memory. This memoize conserves RAM (probably :))

      If the same parameter is passed as the last execution, the results are pulled from the cache. When paramers change, the callback is reevaluated for new results.

      The key difference between [[func.memoize]] is that this memoize stores just the last results as opposed to a dictionary of all previous results.

      If running a lot of executions, this can save memory.

      Consider the following example. The calculations are done only when a mutation occurs in the parameters. Otherwise, the results are pull from the single cache.

      let expensiveCalculation = func.memoizeSimple((a,b,c)=> {
      return a + b + c;
      })

      expensiveCalculation(1, 1, 1); // 3, callback executed and results cached.
      expensiveCalculation(1, 1, 1); // 3 from cache
      expensiveCalculation(1, 1, 1); // 3 from cache
      expensiveCalculation(1, 1, 1); // 3 from cache

      expensiveCalculation(2, 2, 2); // 6, callback executed and results cached.
      expensiveCalculation(2, 2, 2); // 6 from cache

      // Now in a classic memozize the below would not be reexecuted. But since
      // this memoize only has a simple memory, it will be reexecuted.
      expensiveCalculation(1, 1, 1); // 3, callback executed and results cached.
      expensiveCalculation(1, 1, 1); // 3 from cache

      Parameters

      • callback: Function

        The function to wrap the memoize mechanism. It's expect that this function returns something. Can't be void.

      Returns Function