Last active
August 29, 2015 14:11
-
-
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.
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
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