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

Enumerable:single

Returns the only value in an iterable, optionally restricted by a predicate.

Syntax

value = values:single(predicate)

Parameters

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

Returns

The only value, or the only matching value.

Remarks

Raises an error when there are no matches or more than one match.

Example

local selectedTarget = LuaQ.from({
    { name = "General Graardor", marked = false },
    { name = "Sergeant Steelwill", marked = true },
    { name = "Sergeant Grimspike", marked = false },
})
    :single(function(npc) return npc.marked end)
-- selectedTarget.name is "Sergeant Steelwill"

See also

SingleOrDefault · First · Functions

Clone this wiki locally