Skip to content

TiddoLangerak/memoize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Module to memoize function results for any number of arguments.

Requirements

A modern ES6 environment (may be transpiled)

Example usage

import memoize from '@tiddo/memoize';

const fibonacci = memoize((n) => {
	if (n < 1) {
		return 1;
	}
	return fibonacci(n-1) + fibonacci(n-2);
});

API

import memoize, { forget, forgetAll } from '@tiddo/memoize';

const f = memoize(func)

Returns a memoized version of func. The function is memoized on all it's arguments (e.g. f(a) !== f(a,a));

forget(f, ...args)

Forgets the memoized result for the given memoized function and arguments.

forgetAll(f)

Clears the entire memoization cache for the given function.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published