Last active
March 21, 2020 16:04
-
-
Save Fingercomp/13c0add5e0bbeeac7fa90730172f7277 to your computer and use it in GitHub Desktop.
A slick formatter for the insane
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 format(arg) | |
local function expand(v) | |
if type(v) == "string" then | |
return v | |
elseif type(v) == "table" then | |
return tostring(v[1]) | |
end | |
error("unsupported type") | |
end | |
local function curry(f, state) | |
return function(v) | |
return f(state, v) | |
end | |
end | |
local function handler(state, v) | |
if v == nil then | |
return state | |
end | |
return curry(handler, state .. expand(v)) | |
end | |
return handler("", arg) | |
end | |
local myVar = 42 | |
local bold = "{bold marker}" | |
print(format "myVar = " {myVar} "; " {bold} "bold, if not daring" ()) | |
--> myVar = 42; {bold marker}bold, if not daring |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment