Commit 6df3b42d authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Migrate memoize module to TS

parent 0f427d89
......@@ -4,21 +4,16 @@
*
* The argument to the input function may be of any type and is compared
* using reference equality.
*
* @template Arg
* @template Result
* @param {(arg: Arg) => Result} fn
* @return {(arg: Arg) => Result}
*/
export function memoize(fn) {
export function memoize<Arg, Result>(
fn: (arg: Arg) => Result
): (arg: Arg) => Result {
if (fn.length !== 1) {
throw new Error('Memoize input must be a function of one argument');
}
/** @type {Arg} */
let lastArg;
/** @type {Result} */
let lastResult;
let lastArg: Arg;
let lastResult: Result;
return function (arg) {
if (arg === lastArg) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment