Last active
December 4, 2016 21:39
-
-
Save bwestergard/d8b24846816d7670af901dc1ba7094ec to your computer and use it in GitHub Desktop.
Lazy Streams in Node
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
"use strict"; | |
// http://stackoverflow.com/questions/23260390/node-js-tail-call-optimization-possible-or-not | |
// Tested and working with node v7.2.0. Both of the following work: | |
// node --harmony_tailcalls tco.js | |
// node --harmony tco.js | |
const natsFrom = (n) => [n, () => natsFrom(n+1)] | |
const kth = ([hd, tl], k) => k === 0 ? hd : kth(tl(), k - 1) | |
console.log( | |
kth(natsFrom(1337), 8000000) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment