aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2011-12-07 05:04:55 +0000
committerMatthew Wild <mwild1@gmail.com>2011-12-07 05:04:55 +0000
commit0572f1ef240e909b4e16feda8964e56cfb1aa982 (patch)
treeb0012455948af3da83a9c2328d014c87189b5f8b /util
parent1ef4ed4ad00f546da835900daa15687613982b6b (diff)
downloadprosody-0572f1ef240e909b4e16feda8964e56cfb1aa982.tar.gz
prosody-0572f1ef240e909b4e16feda8964e56cfb1aa982.zip
util.array: Add pluck() method to pick a given property from each item
Diffstat (limited to 'util')
-rw-r--r--util/array.lua7
1 files changed, 7 insertions, 0 deletions
diff --git a/util/array.lua b/util/array.lua
index 5dbd3037..cf586214 100644
--- a/util/array.lua
+++ b/util/array.lua
@@ -60,6 +60,13 @@ function array_base.sort(outa, ina, ...)
return outa;
end
+function array_base.pluck(outa, ina, key)
+ for i=1,#ina do
+ outa[i] = ina[i][key];
+ end
+ return outa;
+end
+
--- These methods only mutate
function array_methods:random()
return self[math.random(1,#self)];