Skip to content

Instantly share code, notes, and snippets.

@kunigami

kunigami/coroutine_pipe.py

Last active Jan 29, 2020
Embed
What would you like to do?
def get_words(step):
f = open('/usr/share/dict/words', 'r')
for line in f:
step.send(line.strip())
@coroutine
def filter_step(step):
while True:
line = (yield)
if (line[-3:] == 'ion'):
step.send(line)
@coroutine
def print_step():
while True:
line = (yield)
print(line)
p = print_step()
f = filter_step(p)
get_words(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.