Last active
September 27, 2016 08:54
-
-
Save StiviiK/9736d02a1163ea746e04 to your computer and use it in GitHub Desktop.
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 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