Skip to content

Instantly share code, notes, and snippets.

@logarytm
Last active August 11, 2018 19:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save logarytm/6bf3865ee2efa7f5bf63a30ea8a00b6c to your computer and use it in GitHub Desktop.
Save logarytm/6bf3865ee2efa7f5bf63a30ea8a00b6c to your computer and use it in GitHub Desktop.
range() without loops or recursion… or is it?
(f => (g => g(g))(g => f(x => g(g)(x))))((x) => ([a, b, c = 1]) => a === b ? [a] : [a, ...x([a + c, b, c])])([1, 10])
// [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
// Note: Functional programmers and mathematicians have known this trick
// for decades under the name of a Y combinator. I did not invent this.
// I recommend deciphering this thing on your own, though.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment