3 ms·
I find Matt Might's post on this topic (Y in JavaScript) the best I seen (even though it's at least 8 years old by now): http://matt.might.net/articles/implemen
by markc 8y ago
I find Matt Might's post on this topic (Y in JavaScript) the best I seen (even though it's at least 8 years old by now): http://matt.might.net/articles/implementation-of-recursive-fixed-point-y-combinator-in-javascript-for-memoization/ http://matt.might.net/articles/implementation-of-recursive-f...
It's clear, minimalist, insightful, and even has an in-page live code demo. Bonus points for including fixed-points as a key concept, and memoization as an extremely useful technique.
- braythwayt 8y agoI've always liked that post, and I think it inspired me to do a similar thing. That being said, I'm a big fan of decorators, so I expressed the memoization using a decorator, rather than baking it into Ymem. On the other hand, trampolining is the perfect application for a special-purpose Y combinator, and thus the decoupled Trampoline.