Created
February 13, 2020 06:10
-
-
Save gsscoder/2d684ec40b1a2e931e6653f0d7630a99 to your computer and use it in GitHub Desktop.
Simple TypeScript iterator example
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 yieldNumbers() : IterableIterator<number> { | |
return generator() | |
function *generator(): IterableIterator<number> { | |
yield 0 | |
yield 1 | |
yield 2 | |
yield 3 | |
} | |
} | |
for(let num of yieldNumbers()) { | |
console.log(num) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment