Last active
March 22, 2022 02:46
-
-
Save dhilst/ff2e51f3014bf9d58e6dd66b75fdfa55 to your computer and use it in GitHub Desktop.
generators as functions
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
def gen(start, f): | |
return lambda: (start, gen(f(start), f)) | |
def inc(a): | |
return a + 1 | |
g = gen(0, inc) | |
while True: | |
x, g = g() | |
print(x) | |
if x == 11: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment