Skip to content

Instantly share code, notes, and snippets.

@therealklanni
Last active August 29, 2015 14:00
Show Gist options
  • Save therealklanni/11468674 to your computer and use it in GitHub Desktop.
Save therealklanni/11468674 to your computer and use it in GitHub Desktop.
Memoized Y-combinator
// Y-combinator with memoization
var Yc = function (f, x) {
x = x || {};
return function () {
var y = JSON.stringify([].slice.call(arguments));
return x[y] || (x[y] = f(function (z) {
return Yc(f, x)(z);
}).apply(this, arguments));
};
};
@therealklanni
Copy link
Author

Slightly improved hashing. (Borrowed from Addy's blog)

@jsdevel
Copy link

jsdevel commented May 2, 2014

Array.prototype.slice.call(arguments)
[].slice.call(arguments)

@therealklanni
Copy link
Author

If you look at the revisions, that's what I had originally. I copy/pasted the var and while statement from the blog post noted in my previous comment, so my version ([].slice.call(arguments)) got replaced by Addy's version. :P

@jsdevel
Copy link

jsdevel commented May 3, 2014

:P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment