Created
March 16, 2015 22:40
-
-
Save jni/2f69d1c37e1995267824 to your computer and use it in GitHub Desktop.
Python generators and piping demo
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
times2 start | |
range start | |
yielding 0 | |
multiplying 0 by 2 | |
yielding 1 | |
multiplying 1 by 2 | |
yielding 2 | |
multiplying 2 by 2 | |
yielding 3 | |
multiplying 3 by 2 | |
yielding 4 | |
multiplying 4 by 2 | |
range done | |
times2 done |
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
from cytoolz import pipe | |
def myrange(m): | |
print("range start") | |
for i in range(m): | |
print("yielding %i" % i) | |
yield i | |
print("range done") | |
def times2(it): | |
print("times2 start") | |
for i in it: | |
print("multiplying %i by 2" % i) | |
yield i * 2 | |
print ("times2 done") | |
if __name__ == '__main__': | |
pipe(5, myrange, times2, list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment