Memoization caches a function's results keyed by its arguments, so repeated calls with the same inputs return the cached result instantly instead of recomputing. It trades memory for speed and only works for pure functions (same input → same output, no side effects).
A generic memoize wrapper
js
() {
cache = ();
{
key = .(args);
(cache.(key)) {
cache.(key);
}
result = (...args);
cache.(key, result);
result;
};
}
= n => { n * n; };
fastSquare = (slowSquare);
();
();
