StarryInternet / map-memo

Generic memoization with Map and WeakMap
MIT License
10 stars 1 forks source link

Can it work with functions as arguments? #5

Open bugeats opened 4 years ago

bugeats commented 4 years ago

Neat project. It doesn't seem to cache if a named function is used as a argument to the memoized function. Is this possible with WeakMap/Map?

kevincennis commented 4 years ago

It should work for named functions.

function caller( fn ) {
  return fn();
}

function rand() {
  return Math.random();
}

const mem = memoize( caller );

mem( rand ) === mem( rand ); // true

Can you post an example of what you're trying that doesn't seem to work?