Skip to content
Snippets Groups Projects
Commit 68b4f955 authored by Alexander Rose's avatar Alexander Rose
Browse files

memoize docs

parent 4c5eb4a9
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@
* @author David Sehnal <david.sehnal@gmail.com>
*/
/** Cache the latest result from calls to a function with any number of arguments */
export function memoizeLatest<Args extends any[], T>(f: (...args: Args) => T): (...args: Args) => T {
let lastArgs: any[] | undefined = void 0, value: any = void 0;
return (...args) => {
......@@ -23,6 +24,7 @@ export function memoizeLatest<Args extends any[], T>(f: (...args: Args) => T): (
}
}
/** Cache all results from calls to a function with a single argument */
export function memoize1<A, T>(f: (a: A) => T): (a: A) => T {
const cache = new Map<A, T>();
return a => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment