Skip to content

Instantly share code, notes, and snippets.

@Varriount
Last active December 28, 2015 19:19
Show Gist options
  • Save Varriount/7549683 to your computer and use it in GitHub Desktop.
Save Varriount/7549683 to your computer and use it in GitHub Desktop.
Look ma, it's a generator!
iterator additionIterator(value: int): int {.closure.} =
var total = 0
while True:
total += value
yield total
var addIter = additionIterator # Creates a *copy* of the original iterator procedure
for i in 1..5:
echo(addIter(i)) # The argument the iterator takes is updated each time we call it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment