Created
December 8, 2018 06:56
-
-
Save technicallyagd/743ba344d185f168b932962309f3b919 to your computer and use it in GitHub Desktop.
Nim iterator used like generator in python
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
let numbers = @[2, 6, 3, 8, 5] | |
iterator read(): int{.closure.} = | |
for n in numbers: | |
yield n | |
proc main() = | |
var | |
first = read | |
second = read | |
echo first() | |
echo second() | |
# ############################################################################ | |
when isMainModule: | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
working version of @anamok original code http://ix.io/1vvk/nim