add several utility functions related to tables.
create api functions `any`, `every`, and `underride`. `any` and `every` checks if a condition is true for any and every item in a table, respectively. `underride` returns a table that defaults to a provided table, for items that aren't specified in the other provided table.
This commit is contained in:
parent
33fbd7c35e
commit
5a3d81787c
|
@ -26,3 +26,26 @@ function blockgame.shuffle (tab)
|
|||
end
|
||||
return result
|
||||
end
|
||||
|
||||
function blockgame.any (tab, check)
|
||||
for key, value in pairs(tab) do
|
||||
if check(value, key, tab) then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function blockgame.every (tab, check)
|
||||
for key, value in pairs(tab) do
|
||||
if not check(value, key, tab) then return false end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function blockgame.underride (tab, template)
|
||||
local tab = tab or {}
|
||||
local result = blockgame.shallow_copy_table(template)
|
||||
for key, value in pairs(tab) do
|
||||
result[key] = value
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue