Skip to content

Instantly share code, notes, and snippets.

@michelrandahl
Last active July 9, 2016 16: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 michelrandahl/edb3eb9700fd28ceb5b766b0a8981521 to your computer and use it in GitHub Desktop.
Save michelrandahl/edb3eb9700fd28ceb5b766b0a8981521 to your computer and use it in GitHub Desktop.
pipeline function in Lua
function pipe(data, ...)
local n = select("#", ...)
if n == 0 then
return data
else
local funs = {...}
local f = table.remove(funs, 1)
return pipe(f(data), unpack(funs))
end
end
local res = pipe(
"hej",
function(x) return x .. " 1 " end,
function(x) return x .. " 2 " end
)
print(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment