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

Enumerable:last

Returns the last value in an iterable, optionally requiring a predicate match.

Syntax

value = values:last(predicate)

Parameters

Parameter Type Description
predicate function(value, sourceKey) (optional) Returns true for a matching value.

Returns

The last value, or the last value whose predicate returns exactly true.

Remarks

Raises an error if the iterable is empty or no value matches. For dictionary- like tables, pairs order is unspecified, so “last” is not predictable.

Example

local latestUpgrade = LuaQ.from({
    { item = "rune helm", tier = 1 },
    { item = "dragon helm", tier = 2 },
    { item = "masterwork helm", tier = 3 },
})
    :last(function(gear) return gear.tier >= 2 end)
-- latestUpgrade.item is "masterwork helm"

See also

First · LastOrDefault · Functions

Clone this wiki locally