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

Enumerable:max

Returns the maximum value, or the original item whose selected value is maximum.

Syntax

maximum = values:max(selector)

Parameters

Parameter Type Description
selector function(value, sourceKey) (optional) Selects the value used for comparison.

Returns

Without a selector, returns the maximum value. With a selector, returns the original value that has the maximum selected value.

Remarks

The iterable must contain at least one value. Values or selected values must support Lua's < comparison.

Example

local highestLevelPlayer = LuaQ.from({
    { name = "Ada", level = 92 },
    { name = "Bryn", level = 78 },
    { name = "Cato", level = 99 },
})
    :max(function(player) return player.level end)
-- highestLevelPlayer.name is "Cato"

See also

Min · Sum · Functions

Clone this wiki locally