Share your code. Components are building blocks, you are the architect.

utils/memoize-with
v1.1.0
1.1.0
1.0.0
MIT
PUBLIC
3
Build: fail
BuildFail
Build Status: fail
A customisable version of [`R.memoize`](#memoize)

Please configure Bit as a scoped registry to install components with NPM.Learn more

npm config set '@bit:registry' https://node.bitsrc.io
Use utils/memoize-with in your project
npm i @bit/bit.ramda.utils.memoize-with
Copied

memoizeWith (fn:Function, fn:Function) : Function

A customisable version of R.memoize. memoizeWith takes an additional function that will be applied to a given argument set and used to create the cache key under which the results of the function to be memoized will be stored. Care must be taken when implementing key generation to avoid clashes that may overwrite previous entries erroneously.

Example

let count = 0;
     const factorial = R.memoizeWith(R.identity, n => {
       count += 1;
       return R.product(R.range(1, n + 1));
     });
     factorial(5); //=> 120
     factorial(5); //=> 120
     factorial(5); //=> 120
     count; //=> 1

Arguments

fn: Function

The function to generate the cache key.

fn: Function

The function to memoize.

Returns

Function

Memoized version of `fn`.