Created
December 19, 2013 19:50
-
-
Save calvingiles/8045105 to your computer and use it in GitHub Desktop.
auto-incrementor and infinate list
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
""" | |
>>> I = ai(start=0, step=1) | |
>>> I() | |
0 | |
>>> I() | |
1 | |
>>> J = ai(start=0, step=1) | |
>>> J() | |
0 | |
>>> I() | |
2 | |
>>> J() | |
1 | |
""" | |
def infinate_list(start, step): | |
# infinate list generator | |
while(True): | |
yield start | |
start += step | |
def ai(start=0, step=1): | |
# auto-incrementer factory function | |
il = infinate_list(start, step) | |
return lambda: il.next() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment