Anonymous

Module:FunList/Iterators: Difference between revisions

From Melvor Idle
no edit summary
No edit summary
No edit summary
Line 73: Line 73:
     if self.state == 0 then
     if self.state == 0 then
         self.state = 1
         self.state = 1
self.index = self.isArray and 0 or nil
     end
     end


Line 98: Line 99:
-- they just call moveNext on the enumerator instead.
-- they just call moveNext on the enumerator instead.
function TableEnumerator:getEnumerator(isArray)
function TableEnumerator:getEnumerator(isArray)
local instance = nil
    local instance = (self.state == 0) and self or TableEnumerator.new(self.tbl)
if self.state == 0 then
    instance.isArray = isArray
instance = self
    return instance
else
instance = TableEnumerator.new(self.tbl)
end
instance.isArray = isArray
return instance
end
end


Line 145: Line 141:
end
end


function SelectEnumerator:getEnumerator()
function SelectEnumerator:getEnumerator(isArray)
if self.state == 0 then
    local instance = (self.state == 0) and self or SelectEnumerator.new(self.source, self.selector)
return self
    instance.isArray = isArray
else
    return instance
return SelectEnumerator.new(self.source, self.selector)
end
end
end


Line 156: Line 150:
local WhereEnumerator = setmetatable({}, { __index = Enumerator })
local WhereEnumerator = setmetatable({}, { __index = Enumerator })
WhereEnumerator.__index = WhereEnumerator
WhereEnumerator.__index = WhereEnumerator
WhereEnumerator.__pairs = Enumerator_mt.__pairs
WhereEnumerator.__pairs = Enumerator_mt.__pairs
WhereEnumerator.__ipairs = Enumerator_mt.__ipairs
WhereEnumerator.__ipairs = Enumerator_mt.__ipairs


Line 191: Line 185:


function WhereEnumerator:getEnumerator()
function WhereEnumerator:getEnumerator()
if self.state == 0 then
    local instance = (self.state == 0) and self or WhereEnumerator.new(self.source, self.predicate)
return self
    instance.isArray = isArray
else
    return instance
return WhereEnumerator.new(self.source, self.predicate)
end
end
end


Line 260: Line 252:




function SelectManyEnumerator:getEnumerator()
function SelectManyEnumerator:getEnumerator(isArray)
if self.state == 0 then
local instance = (self.state == 0) and self or SelectManyEnumerator.new(self.source, self.selector)
return self
    instance.isArray = isArray
else
    return instance
return SelectManyEnumerator.new(self.source, self.predicate)
end
end
end


2,875

edits