Anonymous

Module:FunList/Iterators: Difference between revisions

From Melvor Idle
no edit summary
No edit summary
No edit summary
Line 33: Line 33:
end
end


function Enumerator:getEnumerator(startIndex)
function Enumerator:getEnumerator(isArray)
error('Not implemented in base class.')
error('Not implemented in base class.')
end
end
Line 40: Line 40:
function Enumerator:overridePairs(startIndex)
function Enumerator:overridePairs(startIndex)
-- Get or create clean enumerator. This ensures the state is 0.
-- Get or create clean enumerator. This ensures the state is 0.
local enum = self:getEnumerator(startIndex)
local enum = self:getEnumerator(startIndex == 0)
enum.current = nil
enum.current = nil
enum.index = startIndex
enum.index = startIndex
Line 97: Line 97:
-- as an array or as a mixed table. It is ignored in the other enumerators as
-- as an array or as a mixed table. It is ignored in the other enumerators as
-- they just call moveNext on the enumerator instead.
-- they just call moveNext on the enumerator instead.
function TableEnumerator:getEnumerator(startIndex)
function TableEnumerator:getEnumerator(isArray)
local instance = nil
local instance = nil
if self.state == 0 then
if self.state == 0 then
Line 104: Line 104:
instance = TableEnumerator.new(self.tbl)
instance = TableEnumerator.new(self.tbl)
end
end
mw.log(startIndex == 0)
instance.isArray = isArray
instance.isArray = startIndex == 0
return instance
return instance
end
end
Line 113: Line 112:
SelectEnumerator.__index = SelectEnumerator
SelectEnumerator.__index = SelectEnumerator
SelectEnumerator.__pairs = Enumerator_mt.__pairs
SelectEnumerator.__pairs = Enumerator_mt.__pairs
SelectEnumerator.__ipairs = Enumerator_mt.__ipairs


function SelectEnumerator.new(source, selector)
function SelectEnumerator.new(source, selector)
Line 157: Line 157:
WhereEnumerator.__index = WhereEnumerator
WhereEnumerator.__index = WhereEnumerator
WhereEnumerator.__pairs = Enumerator_mt.__pairs
WhereEnumerator.__pairs = Enumerator_mt.__pairs
WhereEnumerator.__ipairs = Enumerator_mt.__ipairs


function WhereEnumerator.new(source, predicate)
function WhereEnumerator.new(source, predicate)
Line 201: Line 202:
SelectManyEnumerator.__index = SelectManyEnumerator
SelectManyEnumerator.__index = SelectManyEnumerator
SelectManyEnumerator.__pairs = Enumerator_mt.__pairs
SelectManyEnumerator.__pairs = Enumerator_mt.__pairs
SelectManyEnumerator.__ipairs = Enumerator_mt.__ipairs


function SelectManyEnumerator.new(source, selector)
function SelectManyEnumerator.new(source, selector)
2,875

edits