memoize
Optimises subsequent calls of a function by caching return values.
Usage
ts
import { memoize } from '@screaming/utils'
const add = memoize((x: number, y: number) => {
return x + y
})
add(1, 2)
// calculates 3
add(1, 2)
// obtains 3 from cache
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
Type Definitions
ts
/**
* @param fn - The function.
* @returns The memoized function.
*/
export declare function memoize<T>(fn: (...args: any[]) => T): (...args: any[]) => T
1
2
3
4
5
2
3
4
5