Last active
July 9, 2016 16:06
-
-
Save michelrandahl/edb3eb9700fd28ceb5b766b0a8981521 to your computer and use it in GitHub Desktop.
pipeline function in Lua
This file contains hidden or 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
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