2,875
edits
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 | 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 | 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 | 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 = | 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 = | 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) |
edits