1.0.0 • Published 4 years ago
memoize-pure v1.0.0
Install
$ npm i memoize-pureAPI
Table of Contents
memoize
Memoize a function.
const fn = memoize((a, b, c) => some_expensive_calls(a, b, c))
...
const result = fn(1, 2, 3) // => calls the inner function and saves arguments signature "1,2,3"
...
const result = fn(1, 2, 3) // => returns the memoized result immediately since "1,2,3" matches memoryParameters
fnany The function to memoizemapA map object to use as memory (optional, defaultObject.create(null))
Returns any The memoized function
memoizeDebug
Debug memoize a function.
const fn = memoizeDebug((a, b, c) => some_expensive_calls(a, b, c))
...
const result = fn(1, 2, 3) // => calls the inner function and saves arguments signature "1,2,3"
...
const result = fn(1, 2, 3) // => returns the memoized result immediately since "1,2,3" matches memory
fn.__memoizeTimesCalled__ // => 1
fn.__memoizeMap__ // => { '1,2,3': 'some result' }Parameters
fnany The function to memoizemap(optional, defaultObject.create(null))threshold(optional, defaultInfinity)
Returns any The memoized function including two properties:* __memoizeMap__ is the memory map of arguments and results
__memoizeTimesCalled__is the count that the wrapped function has been called
Contribute
All contributions are welcome!
License
MIT © 2021 stagas
1.0.0
4 years ago