Skip to content

Instantly share code, notes, and snippets.

@calvingiles
Created December 19, 2013 19:50
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 calvingiles/8045105 to your computer and use it in GitHub Desktop.
Save calvingiles/8045105 to your computer and use it in GitHub Desktop.
auto-incrementor and infinate list
"""
>>> 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