Repository navigation
LastOrDefault
Dennis Corvers edited this page Oct 23, 2026
·
1 revision
Returns the last value in an iterable, or a default when there is no match.
value = values:lastOrDefault(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 last value, the last matching value, or defaultValue when none exists.
Pass nil as the predicate to provide only a default value. Valid false
values are preserved. For dictionary-like tables, iteration order is
unspecified.
local finalUpgrade = LuaQ.from({
{ item = "rune helm", tier = 1 },
{ item = "dragon helm", tier = 2 },
})
:lastOrDefault(function(gear) return gear.tier >= 3 end,
{ item = "No upgrade found" })
-- finalUpgrade.item is "No upgrade found"- 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