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

Enumerable:first

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

Syntax

value = values:first(predicate)

Parameters

Parameter Type Description
predicate function(value, sourceKey) (optional) Returns true for the desired value.

Returns

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

Remarks

Raises an error if the iterable is empty or no value matches. With a predicate, the callback receives the source iterator key.

Example

local firstVeteran = LuaQ.from({
    { name = "Ada", level = 42 },
    { name = "Bryn", level = 81 },
    { name = "Cato", level = 93 },
})
    :first(function(player) return player.level >= 80 end)
-- firstVeteran.name is "Bryn"

See also

FirstOrDefault · Last · Single · Functions

Clone this wiki locally