Changeset

4439:1c8d2c0d02db

util.array: Add pluck() method to pick a given property from each item
author Matthew Wild <mwild1@gmail.com>
date Wed, 07 Dec 2011 05:04:55 +0000
parents 4438:7f51186ed28b
children 4440:c60ed6732b34
files util/array.lua
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/util/array.lua	Wed Dec 07 04:57:51 2011 +0000
+++ b/util/array.lua	Wed Dec 07 05:04:55 2011 +0000
@@ -60,6 +60,13 @@
 	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)];