util.array: Add array.collect() to collect results from iterators into an array, and use module() to correctly set the module name

Wed, 22 Apr 2009 17:46:17 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 22 Apr 2009 17:46:17 +0100
changeset 1027
fe2e3d3dba6a
parent 1026
e640df2e4e9b
child 1028
594a07e753a0

util.array: Add array.collect() to collect results from iterators into an array, and use module() to correctly set the module name

util/array.lua file | annotate | diff | comparison | revisions
--- a/util/array.lua	Tue Apr 21 22:05:21 2009 +0100
+++ b/util/array.lua	Wed Apr 22 17:46:17 2009 +0100
@@ -52,4 +52,17 @@
 	end
 end
 
-_G.array = array 
+function array.collect(f, s, var)
+	local t, var = {};
+	while true do
+		var = f(s, var);
+	        if var == nil then break; end
+		table.insert(t, var);
+	end
+	return setmetatable(t, array_mt);
+end
+
+_G.array = array;
+module("array");
+
+return array;

mercurial