Skip to content

Aggregate

Dennis Corvers edited this page Oct 23, 2026 · 1 revision

Enumerable:aggregate

Reduces all values to one result using an accumulator function.

Syntax

result = values:aggregate(func, seed, resultSelector)

Parameters

Parameter Type Description
func function(accumulator, value) Produces the next accumulator value.
seed any (optional) Initial accumulator. If omitted or nil, the first source value is used.
resultSelector function(result) (optional) Transforms the final accumulator.

Returns

The final accumulator, optionally transformed by resultSelector.

Remarks

An empty source without a seed raises an error. fold and reduce are aliases of aggregate.

Example

local totalCoins = LuaQ.from({
    { player = "Ada", coins = 120 },
    { player = "Bryn", coins = 85 },
})
    :aggregate(function(total, entry)
        return total + entry.coins
    end, 0)
-- 205

See also

Count · Sum · Functions

Clone this wiki locally