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 @@ ...@@ -4,21 +4,16 @@
* *
* The argument to the input function may be of any type and is compared * The argument to the input function may be of any type and is compared
* using reference equality. * 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) { if (fn.length !== 1) {
throw new Error('Memoize input must be a function of one argument'); throw new Error('Memoize input must be a function of one argument');
} }
/** @type {Arg} */ let lastArg: Arg;
let lastArg; let lastResult: Result;
/** @type {Result} */
let lastResult;
return function (arg) { return function (arg) {
if (arg === lastArg) { 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