A variant of lodash's memoize function that remembers only one result, the last one.
npm install lomemo-one
import lomemoOne from 'lomemo-one';
// Let's memoize a function, using the first argument as the key
const memoized = lomemoOne ( ( a, b ) => a + b );
memoized ( 1, 2 ); // => 3
memoized ( 1, 5 ); // => 3
memoized ( 2, 8 ); // => 10
memoized ( 1, 5 ); // => 6
// Let's memoize a function, using a custom function to generate the key
const resolver = ( ...args ) => args.join ( '' );
const memoized = lomemoOne ( ( a, b ) => a + b, resolver );
memoized ( 1, 2 ); // => 3
memoized ( 1, 5 ); // => 6
memoized ( '', '15' ); // => 6
memoized ( 2, 8 ); // => 10
memoized ( '', '15' ); // => '15'
MIT © Fabio Spampinato