Last active
August 29, 2015 14:00
-
-
Save therealklanni/11468674 to your computer and use it in GitHub Desktop.
Memoized Y-combinator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)); | |
}; | |
}; |
Array.prototype.slice.call(arguments)
[].slice.call(arguments)
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
:P
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Slightly improved hashing. (Borrowed from Addy's blog)