isempty

function isempty( tab ) --> res

Description

Returns true if a table contains values.

Parameters

tab

Table that should be checked.

Return Values

res

true if the table contains no values, otherwise false.

Code

--ZFUNC-isempty-v1
local function isempty( tab ) --> res
   for _, v in pairs( tab ) do return false end
   return true
end

return isempty

Examples

local t = require( "taptest" )
local isempty = require( "isempty" )

t( isempty{}, true )
t( isempty{ 1, 2, 3 }, false )

local tab = { single_value="1" }
t( isempty( tab ), false )
tab.single_value = nil
t( isempty( tab ), true )

t()

Inspired by

See also