Memoization cache ir-riżultati ta' funzjoni mehmuza mill-argumenti tagħha, għaldaqstant it-talaghex ripetuti bl-inputs istess jirritorna r-riżultat cache immedjatament minflok li jiġi rikkalkulat. Huwa jitbadal memoria għal veloċità u jaħdem biss għal funzjonijiet pure (input istess → output istess, l-ebda side effects).
Wrapper memoize ġeneriku
js
() {
cache = ();
{
key = .(args);
(cache.(key)) {
cache.(key);
}
result = (...args);
cache.(key, result);
result;
};
}
= n => { n * n; };
fastSquare = (slowSquare);
();
();
