8000 just/packages/function-memoize at patch-1 · hmmhmmhm/just · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
 
 

function-memoize

Folders and files

< 93E5 td colSpan="3" class="f5 text-normal tmp-px-3">

parent directory

..
NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

just-memoize

Part of a library of zero-dependency npm modules that do just do one thing. Guilt-free utilities for every occasion.

Try it now

import memoize from 'just-memoize';

const sumByOne = memoize(function(value) {
  return value + 1;
});

sumByOne(10); // Returns value returned by the function
sumByOne(10); // Cache hit!

sumByOne(20); // Returns value returned by the function
sumByOne(20); // Cache hit!

// Custom cache key (key defaults to JSON stringified arguments)
var sum = memoize(function(a, b) {
  return a + b;
}, function(a, b) {
  return `${a}-${b}`;
});

sum(10, 10); // Returns value returned by the function
sum(10, 20); // Returns value returned by the function
sum(10, 20); // Cache hit!
0