Skip to content

Instantly share code, notes, and snippets.

@jakecoffman
Last active August 29, 2015 14:07
Show Gist options
  • Save jakecoffman/b85098eda7b79c8af512 to your computer and use it in GitHub Desktop.
Save jakecoffman/b85098eda7b79c8af512 to your computer and use it in GitHub Desktop.
transducers in python
def even(gen):
for i in gen:
if i % 2 == 0:
yield i
def stringify(gen):
for i in gen:
yield str(i)
def transduce(gen):
return [i for i in gen]
print transduce(stringify(even(xrange(10))))
# ['0', '2', '4', '6', '8']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment