mirror of
https://github.com/bjc/prosody.git
synced 2025-04-03 21:27:38 +03:00
util.array: pluck: Support default value to avoid holes
This commit is contained in:
parent
7b7084ad68
commit
b4ec6112e4
1 changed files with 6 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue