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

Enumerable:sum

Returns the sum of the values in an iterable, optionally summing selected values.

Syntax

total = values:sum(selector)

Parameters

Parameter Type Description
selector function(value, sourceKey) (optional) Returns the numeric value to add.

Returns

The numeric total. An empty iterable returns 0.

Remarks

Without a selector, each value must be numeric. With a selector, each selected result must be numeric.

Example

local totalHealing = LuaQ.from({
    { potion = "Saradomin brew", healing = 900 },
    { potion = "Saradomin brew", healing = 900 },
    { potion = "Shark", healing = 200 },
})
    :sum(function(food) return food.healing end)
-- 2000

See also

Aggregate · Max · Min · Functions

Clone this wiki locally