Skip to content

Instantly share code, notes, and snippets.

@diogotito
Last active June 18, 2024 14:55
Show Gist options
  • Save diogotito/64861280413ee532e0d0d654f5a0fd81 to your computer and use it in GitHub Desktop.
Save diogotito/64861280413ee532e0d0d654f5a0fd81 to your computer and use it in GitHub Desktop.
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