Module:FunList: Difference between revisions

Sort by multiple properties test
(Undo revision 77686 by Ricewind (talk))
Tag: Undo
(Sort by multiple properties test)
Line 9: Line 9:
     local self = setmetatable({}, funlist)
     local self = setmetatable({}, funlist)
self.mytable = tbl
self.mytable = tbl
self.sortData = {}
return self
return self
end
end
Line 27: Line 28:
return false, nil
return false, nil
end
function funlist:finishSort()
local sortFunc = function(left, right)
for _, sortSelector in pairs(self.sortData) do
local leftVal = sortSelector(left)
local rightVal = sortSelector(right)
if leftVal ~= rightVal then
return leftVal < rightVal
end
end
return true
end
table.sort(self.mytable, sortFunc)
self.sortData = {}
return self.mytable
end
function funlist:sortByTest(selector)
assert(selector)
table.insert(self.sortData, selector)
return self
end
end


2,875

edits