Repository navigation
ToLookup
Dennis Corvers edited this page Oct 23, 2026
·
1 revision
Groups values from an iterable into arrays stored under selected keys.
lookup = values:toLookup(keySelector, elementSelector)| Parameter | Type | Description |
|---|---|---|
keySelector |
function(value, sourceKey) |
Returns the group key. |
elementSelector |
function(value, sourceKey) (optional) |
Projects the value stored in the group. |
A Lua table mapping each selected key to an array of matching values or selected elements.
The key selector is required and must not return nil. The element selector
defaults to the original value. toMultimap is an alias.
local namesByRole = LuaQ.from({
{ name = "Ada", role = "mage" },
{ name = "Bryn", role = "ranger" },
{ name = "Cato", role = "mage" },
})
:toLookup(
function(player) return player.role end,
function(player) return player.name end
)
-- namesByRole.mage is { "Ada", "Cato" }- 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