Enumerable Collect - FireDragon91245/Lua-Linq GitHub Wiki
Consumes an enumerable and builds a result. You can collect directly from the iterator or use constructor/consumer/finalizer style accumulation.
enumerable<T> :collect(consumer: fun(enum: iter<T>): TO): TO
enumerable<K, V>:collect(consumer: fun(enum: iter<K, V>): TO): TO
enumerable<T> :collect(
constructor: fun(): TO,
consumer: fun(acc: TO, item: T)
): TO
enumerable<K, V>:collect(
constructor: fun(): TO,
consumer: fun(acc: TO, key: K, value: V)
): TO
enumerable<T> :collect(
constructor: fun(): TO,
consumer: fun(acc: TO, item: T),
finalizer: fun(acc: TO): TFO
): TFO
enumerable<K, V>:collect(
constructor: fun(): TO,
consumer: fun(acc: TO, key: K, value: V),
finalizer: fun(acc: TO): TFO
): TFOlocal sum = linq.list(1, 2, 3, 4):collect(function(iter)
local total = 0
for value in iter do
total = total + value
end
return total
end)local csv = linq.list("iron", "copper", "steel")
:collect(function() return {} end, function(acc, item)
acc[#acc + 1] = item
end, function(acc)
return table.concat(acc, ", ")
end)