util.array: pluck: Support default value to avoid holes

This commit is contained in:
Matthew Wild 2020-06-04 10:39:12 +01:00
parent 7b7084ad68
commit b4ec6112e4

View file

@ -134,9 +134,13 @@ function array_base.unique(outa, ina)
end);
end
function array_base.pluck(outa, ina, key)
function array_base.pluck(outa, ina, key, default)
for i = 1, #ina do
outa[i] = ina[i][key];
local v = ina[i][key];
if v == nil then
v = default;
end
outa[i] = v;
end
return outa;
end