Skip to content

Commit

Permalink
Add Logic.isDeepEmpty function (#3285)
Browse files Browse the repository at this point in the history
* Add `Logic.isDeepEmpty` function

* as per review
  • Loading branch information
hjpalpha authored Sep 14, 2023
1 parent ea345df commit e6fc460
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions standard/logic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ function Logic.isNotEmpty(val)
end
end

---Checks if a given object (table|string|nil) is deep empty
---i.e. is empty itself or only contains objects that are deep empty
---@param val table|string|nil
---@return boolean
---@overload fun(val: any):false
function Logic.isDeepEmpty(val)
return Logic.isEmpty(val) or type(val) == 'table' and
require('Module:Table').all(val, function(key, item) return Logic.isDeepEmpty(item) end)
end

---Inverse of `Logic.isDeepEmpty`
---@param val table|string|nil
---@return boolean
---@overload fun(val: any):true
function Logic.isNotDeepEmpty(val)
return not Logic.isDeepEmpty(val)
end

---Check if the input is a representation of a boolean
---@param val string|number|boolean|nil
---@return boolean
Expand Down

0 comments on commit e6fc460

Please sign in to comment.