Skip to content

Instantly share code, notes, and snippets.

@Xion Xion/monads.py
Created Mar 23, 2012

Embed
What would you like to do?
Monads in Python!
# Monadic IO
def print_(s):
def _():
print s
return _
def some_io():
for x in ['Hello', 'World']:
yield print_(x)
# Runner
def run_monad(m):
try:
x = next(m)
while True:
x = m.send(x())
except StopIteration:
pass
>>> run_monad(some_io())
Hello
World
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.