Anonymous

Module:FunList: Difference between revisions

From Melvor Idle
no edit summary
No edit summary
No edit summary
Line 67: Line 67:
assert(item)
assert(item)
for _, v in pairs(self.mytable) do
for _, v in pairs(self.mytable) do
if funlist.isEqual(v, item) == true then
if self:isEqual(v, item) == true then
return true
return true
end
end
Line 120: Line 120:
-- Returns the last element of a sequence.
-- Returns the last element of a sequence.
function funlist:last()
function funlist:last()
if funlist.any() == false then
if self:any() == false then
error('Sequence contains no items.')
error('Sequence contains no items.')
end
end
Line 132: Line 132:
-- Returns the last element of a sequence, or a default value if no element is found.
-- Returns the last element of a sequence, or a default value if no element is found.
function funlist:lastOrDefault(defaultItem)
function funlist:lastOrDefault(defaultItem)
if funlist.any() == false then
if self:any() == false then
return defaultItem
return defaultItem
end
end
Line 144: Line 144:
-- Returns the maximum value in a sequence of values.
-- Returns the maximum value in a sequence of values.
function funlist:max()
function funlist:max()
local h = funlist:first()
local h = self:first()
for _, v in pairs(self.mytable) do
for _, v in pairs(self.mytable) do
local num = tonumber(v)
local num = tonumber(v)
Line 155: Line 155:
-- Returns the minimum value in a sequence of values.
-- Returns the minimum value in a sequence of values.
function funlist:min()
function funlist:min()
local l = funlist:first()
local l = self:first()
for _, v in pairs(self.mytable) do
for _, v in pairs(self.mytable) do
local num = tonumber(v)
local num = tonumber(v)
2,875

edits