Repository navigation
FirstOrDefault
Dennis Corvers edited this page Oct 23, 2026
·
1 revision
Returns the first value in an iterable, or a default if no value matches.
value = values:firstOrDefault(predicate, defaultValue)| Parameter | Type | Description |
|---|---|---|
predicate |
function(value, sourceKey) (optional) |
Returns true for a matching value. |
defaultValue |
any (optional) | Value returned when there is no match. |
The first value, the first matching value, or defaultValue when none exists.
To provide a default without a predicate, pass nil as the first argument.
Valid false values are preserved.
local nextTask = LuaQ.from({
{ name = "Repair armor", priority = 1 },
{ name = "Restock food", priority = 2 },
})
:firstOrDefault(function(task) return task.priority == 0 end,
{ name = "No urgent task" })
-- nextTask.name is "No urgent task"- 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