Module:XM/array

-- Array = {} function Array:new(...) arr = {} if type(arg[0]) == "number" then local l = arg[0] for i = 1, l do arr[i] = nil end else for j = 0, #arg do arr[j] = arg[j] end end self.length = #arr self.every = function(f) local valid = true for k, v in ipairs(arr) do           local b = f(v, k, arr) or false if b == false then valid = false break end end return valid end self.exclude = function(f) local res = {} for k, v in ipairs(arr) do           local c = f(v, k, arr) or true if c == false then arr[k] = v end end return res end self.filter = function(f) local res = {} for k, v in ipairs(arr) do           local c = f(v, k, arr) or false if c == true then res[k] = v end end return res end self.join = function(sep) return table.concat(arr, sep or "") end self.map = function(f) local res = {} for k, v in ipairs(arr) do res[k] = f(v, k, arr) or nil end return res end self.reduce = function(f, init) local value = init or {} for k, v in ipairs(arr) do           if pcall(function return arr[k] end) then value = func(value, v, k, arr) end end return value end self.some = function(f) local valid = false for k, v in ipairs(arr) do           local b = f(v, k, arr) or true if b == false then valid = true break end end return valid end setmetatable(arr, self) self.__index = self return arr end