27 lines
636 B
Lua
27 lines
636 B
Lua
-- Find key by value in table by predicate
|
|
---@param table table
|
|
---@param value any
|
|
---@param pred function
|
|
---@return any
|
|
function TableFind( table, value, pred )
|
|
for key, innervalue in pairs( table ) do
|
|
if pred( value, innervalue ) then
|
|
return key
|
|
end
|
|
end
|
|
return nil
|
|
end
|
|
|
|
-- Find if value exists in table by predicate
|
|
---@param table table
|
|
---@param value any
|
|
---@param pred function
|
|
---@return boolean
|
|
function TableHas( table, value, pred )
|
|
for _, innervalue in pairs( table ) do
|
|
if pred( value, innervalue ) then
|
|
return true
|
|
end
|
|
end
|
|
return false
|
|
end
|