Anonymous

Module:FunList: Difference between revisions

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


-- Adds elements from one sequence to the other.
function funlist:concat(tbl)
function funlist:concat(tbl)
assert(type(tbl) == 'table')
assert(type(tbl) == 'table')
Line 174: Line 175:
end
end


function funlist:merge(tbl)
-- Adds elements from one sequence to the other by key.
function funlist:join(tbl)
assert(type(tbl) == 'table')
assert(type(tbl) == 'table')
for k, v in pairs(tbl) do
for k, v in pairs(tbl) do
Line 180: Line 182:
end
end
return self
return self
end
function funlist:sort()
table.sort(self.mytable)
return self
end
function funlist:sortBy(selector)
assert(selector)
local sortFunc = function(left, right)
return selector(left) < selector(right)
end
table.sort(self.mytable, sortFunc)
return self
end
function funlist:sortByDecending(selector)
assert(selector)
local sortFunc = function(left, right)
return selector(left) > selector(right)
end
table.sort(self.mytable, sortFunc)
return self
end
end


2,875

edits