Module:FunList/Iterators: Difference between revisions

no edit summary
(Created page with "enumerable = {} local enumerable = {} local enumerable_mt = { __index = enumerable, __pairs = function(t) return t:overridePairs()end } function enumerable.new(tbl) local self = setmetatable({}, enumerable_mt) self.data = tbl self.current = nil self.index = nil return self end function enumerable:moveNext() -- Grab the next index for the internal table. local ix = self.index ix = next(self.data, ix) self.index = ix -- If the index exist, we have succ...")
 
No edit summary
Line 17: Line 17:
function enumerable:moveNext()
function enumerable:moveNext()
-- Grab the next index for the internal table.
-- Grab the next index for the internal table.
local ix = self.index
local key = self.index
ix = next(self.data, ix)
key = next(self.data, key)
self.index = ix
self.index = key
-- If the index exist, we have succesfuly moved to the next.
-- If the index exist, we have succesfuly moved to the next.
if key then
if key then
self.current = self.data[ix]
self.current = self.data[key]
return true
return true
end
end
2,875

edits