Skip to content

Instantly share code, notes, and snippets.

@simon300000
Last active September 18, 2019 22:40
Show Gist options
  • Save simon300000/0beabc3300e0cac8e85bdf736c72a278 to your computer and use it in GitHub Desktop.
Save simon300000/0beabc3300e0cac8e85bdf736c72a278 to your computer and use it in GitHub Desktop.
wow Y combinator.js?
// Simple
const simpleRecursive = () => simpleRecursive()
simpleRecursive()
// "simpleRecursive" is undefined! (static check)
const notSoSimpleRecursive = me => me(me)
notSoSimpleRecursive(notSoSimpleRecursive)
// Don't run forever!
const factorial = (me, n) => n < 1 ? 1 : n * me(me, n - 1)
factorial(factorial, 10)
// Save some lines :D
;((me, n) => n < 1 ? 1 : n * me(me, n - 1))((me, n) => n < 1 ? 1 : n * me(me, n - 1), 10)
// Now we may have a Y Combinator from Lambda Calculus
const againFactorial = x => ((me, n) => n < 1 ? 1 : n * me(me, n - 1))((me, n) => n < 1 ? 1 : n * me(me, n - 1), x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment