Last active
October 19, 2017 02:21
-
-
Save mfix22/3208813b324d82a9ebd197e4b1c3bae8 to your computer and use it in GitHub Desktop.
Y-Combinator in modern JavaScript
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 implemented in JavaScript | |
// Inspired (mostly copied) from http://kestas.kuliukas.com/YCombinatorExplained/ | |
// Thank you! | |
const Y = g => | |
(f => f(f))(f => | |
g(x => f(f)(x))) | |
const factorial = given => | |
n => n < 2 | |
? 1 | |
: n * given(n - 1) | |
// Y(factorial)(5) => 120 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Follow up with multiple args: