jshanson7 / memoize-strict

Strict multi-argument memoization

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

memoize-strict NPM version

Memoization with multi-argument support. Compares arguments with strict equality.

import memoize from 'memoize-strict';

let counter = 0;
const memoizeTest = memoize((a, b) => {
  counter++;
  return typeof a + ' ' + typeof b;
});

memoizeTest(1, true); // => "number boolean"
counter; // => "1"
memoizeTest(1, true); // => "number boolean"
counter; // => "1"

const a = {a: 'a'};
const b = ['b'];
memoizeTest(a, b); // => "object object"
counter; // => "2"
memoizeTest(a, b); // => "object object"
counter; // => "2"

memoizeTest({a: 'a'}, ['b']); // => "object object"
counter; // => "3"
memoizeTest({a: 'a'}, ['b']); // => "object object"
counter; // => "4"

Installation

npm i memoize-strict --save

License

MIT

About

Strict multi-argument memoization


Languages

Language:JavaScript 100.0%