Skip to content

Instantly share code, notes, and snippets.

@zipcode
Created April 16, 2014 19:12
Show Gist options
  • Save zipcode/10922050 to your computer and use it in GitHub Desktop.
Save zipcode/10922050 to your computer and use it in GitHub Desktop.
function id(x) { return x; }
function constant(v) {
return function () {
return v;
}
}
Function.prototype.memoize = function() {
var f = this;
var cache = {};
return function() {
var key = JSON.stringify(arguments);
if (!cache.hasOwnProperty(key)) {
cache[key] = f.apply(null, arguments);
}
return cache[key];
}
}
Function.prototype.compose = function(g) {
var f = this;
return function() {
return f(g.apply(null, arguments));
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment