Repository navigation
GroupBy
Dennis Corvers edited this page Oct 23, 2026
·
2 revisions
Groups source values by a key selected for each value.
groups = source:groupBy(keySelector, elementSelector)| Parameter | Type | Description |
|---|---|---|
keySelector |
function(value) |
Returns the key for the group. |
elementSelector |
function(value) (optional) |
Projects a value before it is added to its group. |
A deferred Enumerable of key/group pairs. Each group is an array of values or
selected elements.
Groups are represented as a lookup table; iteration order between groups is
unspecified. Group keys must be valid Lua table keys and cannot be nil.
local grouped = LuaQ.from({
{ name = "Ada", role = "mage", team = "North" },
{ name = "Bryn", role = "ranger", team = "South" },
{ name = "Cato", role = "mage", team = "North" },
})
:groupBy(
function(player) return player.team end,
function(player) return player.name end
)
:toMap()
-- grouped.North 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