Skip to content

Instantly share code, notes, and snippets.

@gerard-morera
Last active October 10, 2015 13:58
Show Gist options
  • Save gerard-morera/ac82872a5d9e306d2326 to your computer and use it in GitHub Desktop.
Save gerard-morera/ac82872a5d9e306d2326 to your computer and use it in GitHub Desktop.
“Here is a simplified implementation, though there are plenty of more robust versions available.
var memoize = function(f) {
var cache = {};
return function() {
var arg_str = JSON.stringify(arguments);
cache[arg_str] = cache[arg_str] || f.apply(f, arguments);
return cache[arg_str];
};
};
Something to note is that you can transform some impure functions into pure ones by delaying evaluation:
var pureHttpCall = memoize(function(url, params){
return function() { return $.getJSON(url, params); }
});”
Excerpt From: drboolean. “mostly-adequate-guide.” iBooks. https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewBook?id=828C74EE750961AEB99EE55C5B4B538A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment