Last active
June 26, 2016 17:56
-
-
Save trygvea/4eef6cca44e6f56fe10517157359cd91 to your computer and use it in GitHub Desktop.
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
function * Numbers () { | |
let number = 0; | |
while (true) { | |
yield ++number; | |
} | |
} | |
function * take (numberToTake, iterable) { | |
const iterator = iterable[Symbol.iterator](); | |
for (let i = 0; i < numberToTake; ++i) { | |
const { done, value } = iterator.next(); | |
if (!done) yield value; | |
} | |
} | |
for (let n of take(100, Numbers())) {console.log(""+n)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment