aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2017-03-31 17:29:08 +0200
committerKim Alvefur <zash@zash.se>2017-03-31 17:29:08 +0200
commit170f67dd5801afe8ea60ced18500ee50ba10b28b (patch)
tree3558efe7b236bd05a8f2f0148df8e6f9d2275d6b
parent656d2ad6c78aa50ee79020c99e20c061506e7426 (diff)
downloadprosody-170f67dd5801afe8ea60ced18500ee50ba10b28b.tar.gz
prosody-170f67dd5801afe8ea60ced18500ee50ba10b28b.zip
util.array: Add method for filtering out duplicate values
-rw-r--r--util/array.lua12
1 files changed, 12 insertions, 0 deletions
diff --git a/util/array.lua b/util/array.lua
index 05fa97ca..150b4355 100644
--- a/util/array.lua
+++ b/util/array.lua
@@ -92,6 +92,18 @@ function array_base.sort(outa, ina, ...)
return outa;
end
+function array_base.unique(outa, ina)
+ local seen = {};
+ return array_base.filter(outa, ina, function (item)
+ if seen[item] then
+ return false;
+ else
+ seen[item] = true;
+ return true;
+ end
+ end);
+end
+
function array_base.pluck(outa, ina, key)
for i = 1, #ina do
outa[i] = ina[i][key];