Last active
August 29, 2015 13:55
-
-
Save tj/8761361 to your computer and use it in GitHub Desktop.
This file contains 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
def receive(co) | |
let status, val = coroutine.resume(co) | |
return val | |
end | |
def send(x) | |
coroutine.yield(x) | |
end | |
def producer | |
return coroutine.create(def | |
loop | |
let x = io.read() | |
send(x) | |
end | |
end) | |
end | |
def prepend(str, co) | |
return coroutine.create(def | |
loop | |
let x = receive(co) | |
send(str .. x) | |
end | |
end) | |
end | |
def uppercase(co) | |
return coroutine.create(def | |
loop | |
let x = receive(co) | |
send(x:upper()) | |
end | |
end) | |
end | |
def consumer(co) | |
loop | |
let x = receive(co) | |
io.write(x, '\n') | |
end | |
end | |
consumer(prepend('>>> ', uppercase(producer()))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment