Skip to content

Instantly share code, notes, and snippets.

@StiviiK
Last active September 27, 2016 08:54
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 StiviiK/9736d02a1163ea746e04 to your computer and use it in GitHub Desktop.
Save StiviiK/9736d02a1163ea746e04 to your computer and use it in GitHub Desktop.
local function search (key, elements)
for i, v in ipairs(elements) do
if tostring(v.key) == tostring(key) then
if type(v.value) ~= "function" then
return v.value
else
return v.value()
end
end
end
return false
end
function case (name)
return function(value)
return {key = name, value = value}
end
end
function switch (searchFor)
return function(elements)
local result = search(searchFor, elements)
if not result then
return search("default", elements)
end
return result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment