added group by utility

This commit is contained in:
Simon Hirsig
2015-10-16 13:25:31 +02:00
parent fe17f87b2f
commit 1a02819a66
+15 -1
View File
@@ -234,4 +234,18 @@ function Aux.util.money_string(money)
return format(GSC_1, c)
end
end
end
end
function Aux.util.group_by(tables, keys)
local groups = {}
Aux.util.map(tables, function(table)
for _, group in ipairs(groups) do
if Aux.util.all(keys, function(key) table[key] == group[1][key] end) then
tinsert(group, table)
return
end
end
tinsert(groups, { table })
end)
return groups
end