es-next-tools
Version:
A comprehensive utility library for JavaScript and TypeScript that provides a wide range of functions for common programming tasks, including mathematical operations, date manipulations, array and object handling, string utilities, and more.
18 lines (17 loc) • 708 B
TypeScript
import type { AnyFunction } from '..';
/**
* Creates a memoized version of a function.
* @param {T} fn - The function to memoize.
* @returns {(...args: Parameters<T>) => ReturnType<T> | undefined} A memoized version of the input function.
* @template T
* @example
* const expensiveCalculation = (n) => {
* console.log('Calculating...');
* return n * 2;
* };
* const memoizedCalc = memoize(expensiveCalculation);
*
* console.log(memoizedCalc(5)); // Logs: Calculating... 10
* console.log(memoizedCalc(5)); // Logs: 10 (no calculation, result from cache)
*/
export declare function memoize<T extends AnyFunction>(fn: T, limit?: number): (...args: Parameters<T>) => ReturnType<T> | undefined;