Jump to content

မေႃႇၵျူး:table/sparseIpairs

လုၵ်ႉတီႈ ဝိၵ်ႇသျိၼ်ႇၼရီႇ မႃး

Documentation for this module may be created at မေႃႇၵျူး:table/sparseIpairs/doc

local table_num_keys_module = "Module:table/numKeys"

local function num_keys(...)
	num_keys = require(table_num_keys_module)
	return num_keys(...)
end

--[==[
An iterator which works like `ipairs`, but which works for sparse arrays.]==]
return function(t)
	local keys, i = num_keys(t), 0
	return function()
		i = i + 1
		local k = keys[i]
		if k ~= nil then
			return k, t[k]
		end
	end
end