Software /
code /
prosody
Changeset
1027:fe2e3d3dba6a
util.array: Add array.collect() to collect results from iterators into an array, and use module() to correctly set the module name
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 22 Apr 2009 17:46:17 +0100 |
parents | 1026:e640df2e4e9b |
children | 1028:594a07e753a0 |
files | util/array.lua |
diffstat | 1 files changed, 14 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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;