diff options
author | Matthew Wild <mwild1@gmail.com> | 2020-06-04 10:39:12 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2020-06-04 10:39:12 +0100 |
commit | b4ec6112e4bc4003d3257ccaded21a5c73599db1 (patch) | |
tree | 41321ded415edb6bb6ba07aef9a792fb45ebbb50 /util/array.lua | |
parent | 7b7084ad68dd4c30998a4e5d79ac0e5d04fb08d6 (diff) | |
download | prosody-b4ec6112e4bc4003d3257ccaded21a5c73599db1.tar.gz prosody-b4ec6112e4bc4003d3257ccaded21a5c73599db1.zip |
util.array: pluck: Support default value to avoid holes
Diffstat (limited to 'util/array.lua')
-rw-r--r-- | util/array.lua | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/util/array.lua b/util/array.lua index 32d2d6a5..6e5c8383 100644 --- a/util/array.lua +++ b/util/array.lua @@ -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 |