pico-memoize
v1.0.2
Published
A tiny Javascript memoization library.
Downloads
6
Maintainers
Readme
pico-memoize
A tiny Javascript memoization library.
Usage
//CJS
const memoized = require('pico-memoize');
//ESM
import memoized from 'pico-memoize';
//If using it in the browser, it globalizes the memoized function
function sumPrecise(array){
console.log(array);
return array.reduce((a,b)=>a+b,0);
}
sumPrecise = memoized(sumPrecise);
sumPrecise([1,2,3]); //logs [1,2,3], returns 6
sumPrecise([1,2,3]); //returns 6 without logging anything
function deepEqual(a,b){
// memoization has more uses than you think!
let wrapper = memoized(Object);
return wrapper(a) === wrapper(b);
}