Memoization एक फंक्शनचे परिणाम त्याच्या argument द्वारे की केलेले cache करते, त्यामुळे एकच input सह पुनरावृत्ती call केल्यास cached परिणाम तक्षणी परत येतो पुन्हा computing करण्याऐवजी. ते memory साठी speed trade करते आणि केवळ pure functions साठी काम करते (समान input → समान output, side effects नाहीत).
सामान्य memoize wrapper
js
() {
cache = ();
{
key = .(args);
(cache.(key)) {
cache.(key);
}
result = (...args);
cache.(key, result);
result;
};
}
= n => { n * n; };
fastSquare = (slowSquare);
();
();
