Repository navigation
SingleOrDefault
Dennis Corvers edited this page Oct 23, 2026
·
1 revision
Returns the only value matching an optional predicate, or a default when no value matches.
value = values:singleOrDefault(predicate, defaultValue)| Parameter | Type | Description |
|---|---|---|
predicate |
function(value, sourceKey) (optional) |
Returns true for a matching value. |
defaultValue |
any (optional) | Value returned when there are no matches. |
The only matching value, or defaultValue if there are no matches.
Raises an error when more than one value matches. Pass nil as the predicate
to supply only a default.
local assignedRole = LuaQ.from({
{ player = "Ada", assigned = true },
{ player = "Bryn", assigned = false },
})
:singleOrDefault(function(entry) return entry.assigned end,
{ player = "Unassigned" })
-- assignedRole.player is "Ada"- Home
- Getting Started
-
Functions
- aggregate
- all
- any
- concat
- contains
- count
- create
- createFrom
- deepCopy
- difference
- elementAt
- elementAtOrDefault
- first
- firstOrDefault
- flatMap
- foreach
- groupBy
- groupByResult
- indexOf
- intersect
- ipairs
- last
- lastOrDefault
- map
- max
- min
- pairs
- sequenceEquals
- single
- singleOrDefault
- sort
- sortBy
- sortByDescending
- sortDescending
- sum
- take
- takeWhile
- thenBy
- thenByDecending
- toLookup
- toMap
- toSet
- toTable
- union
- unique
- where
- zip
- Aliases