Last active
December 28, 2015 19:19
-
-
Save Varriount/7549683 to your computer and use it in GitHub Desktop.
Look ma, it's a generator!
This file contains hidden or 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
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