memoize-with

v0.9.6arrow_drop_down
v0.9.6
STATUS
Passing
DOWNLOADS
2
VISIBILITY
Public
PUBLISHED
5 years ago
SIZE
973 B
Creates a new function that, when invoked, caches the result of calling `fn` for a given argument set and returns the result.
1 contributor
Install memoize-with as a package?
Copied
npm i @bit/justin-capalbo.ramda.memoize-with
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.cloud
Component Example
React
React
Vue
Angular
React Native
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
toggle layout
No preview available
modifieddraft
chevron_left
chevron_right
memoizeWith (
fn:Function,
fn:Function
) : Function

Creates a new function that, when invoked, caches the result of calling fn for a given argument set and returns the result. Subsequent calls to the memoized fn with the same argument set will not result in an additional call to fn; instead, the cached result for that set of arguments will be returned.

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`.

Help and resources