# HG changeset patch # User Matthew Wild # Date 1240418777 -3600 # Node ID fe2e3d3dba6ab852a4e4d81143cb41676c316d7c # Parent e640df2e4e9bef68f3138b891b551df057d8e221 util.array: Add array.collect() to collect results from iterators into an array, and use module() to correctly set the module name diff -r e640df2e4e9b -r fe2e3d3dba6a util/array.lua --- 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;