Skip to content

Instantly share code, notes, and snippets.

@LPGhatguy
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LPGhatguy/fd380a87862521ddacd5 to your computer and use it in GitHub Desktop.
Save LPGhatguy/fd380a87862521ddacd5 to your computer and use it in GitHub Desktop.
Function composition operator in Lua using __concat, which might not be the best operator to use.
debug.setmetatable(function() end, {
__concat = function(self, with)
return function(...)
return self(with(...))
end
end
})
local sin = math.sin
print((sin .. sin)(5)) --sin(sin(5))
(print .. string.reverse)("Hello, world!") --print(string.reverse("Hello, world!"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment