When I call the method stream that I made, with any table as argument, I get the error "attempt to call table".
As far as I know this error only occurs when I use a for wrong, but I don't have a for in the code that is executed...
function stream(input)
...
local function _stream(input)
local result = {
_stream = true,
_data = input._data or input,
-- Without the Operation-wrapping no function could access the input
-- Intermediate Operations
concat = function(str) return _concat(input,str) end,
distinct = function(func) return _distinct(input,func) end,
filter = function(func) return _filter(input,func) end,
limit = function(n) return _limit(input,n) end,
map = function(func) return _map(input,func) end,
skip = function(n) return _skip(input,n) end,
sort = function(func) return _sort(input,func) end,
split = function(func) return _split(input,func) end,
-- Terminal Operations
allmatch = function(func) return _allmatch(input,func) end,
anymatch = function(func) return _anymatch(input,func) end,
collect = function(coll) return _collect(input,coll) end,
count = function() return _count(input) end,
foreach = function(func) return _foreach(input,func) end,
max = function(func) return _max(input,func) end,
min = function(func) return _min(input,func) end,
nonematch = function(func) return _nonematch(input,func) end,
reduce = function(init,op) return _reduce(input,init,op) end,
toArray = function() return _toArray(input) end
}
return result
end
if input == nil then
error("input must be of type table, but was nil")
elseif type(input) ~= "table" then
error("input must be of type table, but was a "..type(input)..": "..input)
end
return _stream(input)
end
table.stream = stream
Full Source - Older Version (where the argument gets deleted for some reason)
I want to use the method for a more stream-based programming style. Very similar to this project, but more not only for numbers and with named keys.