-
-
Save luikore/2300067 to your computer and use it in GitHub Desktop.
y combinator in ruby
This file contains 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
# this is a bit shorter than the one I made several years ago | |
def Y f | |
g = -> h, *x { f[h[h], *x] }.curry 2 | |
g[g] | |
end | |
factorial = Y -> f, n { n == 0 ? 1 : f[n - 1] * n } | |
puts factorial.(6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment