Skip to content

Instantly share code, notes, and snippets.

@michelrandahl

michelrandahl/pipe.lua

Last active Jul 9, 2016
Embed
What would you like to do?
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