Skip to content

Instantly share code, notes, and snippets.

@qkdreyer
Created June 9, 2018 12:55
Show Gist options
  • Save qkdreyer/ecdaef8c198a120df3dfe9756c70e532 to your computer and use it in GitHub Desktop.
Save qkdreyer/ecdaef8c198a120df3dfe9756c70e532 to your computer and use it in GitHub Desktop.
ES6 Y Combinator One Liner
// http://kestas.kuliukas.com/YCombinatorExplained/
// https://rosettacode.org/wiki/Y_combinator#JavaScript
//
// const factorial = Y(next => (n) => {
// if (n < 2) return 1;
// return n * next(n - 1);
// });
// console.log(factorial(5)); // 120
const Y = f => (...args) => f(Y(f))(...args);
export default Y;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment