pipeline function in Lua
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
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