Skip to content

Instantly share code, notes, and snippets.

@technicallyagd
Created December 8, 2018 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save technicallyagd/743ba344d185f168b932962309f3b919 to your computer and use it in GitHub Desktop.
Save technicallyagd/743ba344d185f168b932962309f3b919 to your computer and use it in GitHub Desktop.
Nim iterator used like generator in python
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()
@technicallyagd
Copy link
Author

working version of @anamok original code http://ix.io/1vvk/nim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment