Skip to content

Instantly share code, notes, and snippets.

@mvcisback
Last active August 29, 2015 14:06
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 mvcisback/dcc78408f2c2986c9c8a to your computer and use it in GitHub Desktop.
Save mvcisback/dcc78408f2c2986c9c8a to your computer and use it in GitHub Desktop.
src to sink
from infix import or_infix as infix
from more_itertools import consumer
@infix
def to(src, sink):
def _to():
for x in src:
sink.send(x)
return _to
def source():
yield from range(5)
@consumer
def sink():
while True:
x = yield
print(x +1)
def main():
plan = source() |to| sink()
plan()
if __name__ == '__main__':
main()
@mvcisback
Copy link
Author

Output:

1
2
3
4
5

@mvcisback
Copy link
Author

This doesn't compose well atm....doesn't yield output

@mvcisback
Copy link
Author

I think there needs to be a distinction between sending and receiving that's not currently available

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment