diff options
-rw-r--r-- | util/array.lua | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/util/array.lua b/util/array.lua index 9e99a3ec..072b24a7 100644 --- a/util/array.lua +++ b/util/array.lua @@ -52,4 +52,17 @@ function array:reverse() 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; |