Skip to content

A variant of lodash's memoize function that remembers only one result, the last one.

License

Notifications You must be signed in to change notification settings

fabiospampinato/lomemo-one

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lomemo Once

A variant of lodash's memoize function that remembers only one result, the last one.

Install

npm install --save lomemo-once

Usage

import lomemoOnce from 'lomemo-once';

// Memoize a function, using the first argument as the key

const memoized = lomemoOnce ( ( a, b ) => a + b );

memoized ( 1, 2 ); // => 3
memoized ( 1, 5 ); // => 3
memoized ( 2, 8 ); // => 10
memoized ( 1, 5 ); // => 6

// Memoize a function, using a custom function to generate the key

const resolver = ( ...args ) => args.join ( '' );
const memoized = lomemoOnce ( ( a, b ) => a + b, resolver );

memoized ( 1, 2 ); // => 3
memoized ( 1, 5 ); // => 6
memoized ( '', '15' ); // => 6
memoized ( 2, 8 ); // => 10
memoized ( '', '15' ); // => '15'

License

MIT © Fabio Spampinato

About

A variant of lodash's memoize function that remembers only one result, the last one.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published