Skip to content

Instantly share code, notes, and snippets.

@tj

tj/pipe.lua Secret

Created September 4, 2012 00:09
Show Gist options
  • Save tj/1a83f93a8e6192f82b87 to your computer and use it in GitHub Desktop.
Save tj/1a83f93a8e6192f82b87 to your computer and use it in GitHub Desktop.
--- cat 'foo' | uppercase | output
function output(co)
while 1 do
local ok, val = coroutine.resume(co)
if ok then
print(val)
else
return
end
end
end
function uppercase(co)
return coroutine.create(function()
while 1 do
local ok, val = coroutine.resume(co)
if ok then
coroutine.yield(val:upper())
else
return
end
end
end)
end
function cat()
return coroutine.create(function()
coroutine.yield('tobi');
coroutine.yield('loki');
coroutine.yield('jane');
coroutine.yield('luna');
end)
end
output(uppercase(cat()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment