Last active
June 18, 2024 14:55
-
-
Save diogotito/64861280413ee532e0d0d654f5a0fd81 to your computer and use it in GitHub Desktop.
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
local function abcdefu(a, b, c, d, e, ...) | |
print(a) | |
print(b) | |
print(c) | |
print(d) | |
print(e) | |
print(...) | |
return "yay" | |
end | |
local function curry(f, ...) | |
local nparams = debug.getinfo(f, "u").nparams | |
local args = {...} | |
return setmetatable({}, { | |
__call = function(_, ...) -- Screw 1st argument, I have upvalues!! | |
for i = 1, select('#', ...) do | |
args[#args+1] = select(i, ...) | |
end | |
if #args >= nparams then | |
return f(unpack(args)) | |
else | |
return curry(f, unpack(args)) | |
end | |
end | |
}) | |
end | |
print( | |
curry (abcdefu) 'a' 'b' (1, 2) ('e', 'f', 'u') | |
) | |
local tbl = {1, 2, 3} | |
print(0, unpack(tbl), unpack(tbl)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment