Skip to content
Dennis Corvers edited this page Oct 23, 2026 · 2 revisions

Enumerable:thenBy

Adds an ascending sort criterion after the criteria of a previous sort.

Syntax

ordered = source:sortBy(primarySelector):thenBy(selector)

Parameters

Parameter Type Description
selector function(value) Returns the next ascending sort key.

Returns

The sorted Enumerable, with the additional criterion appended.

Remarks

Call thenBy on an Enumerable returned by sort, sortDescending, sortBy, sortByDescending, or another thenBy method. Criteria are evaluated in the order added.

Example

local players = {
    { name = "Bryn", role = "mage" },
    { name = "Ada", role = "mage" },
    { name = "Cato", role = "ranger" },
}

local ordered = LuaQ.from(players)
    :sortBy(function(player) return player.role end)
    :thenBy(function(player) return player.name end)
    :map(function(player) return player.name end)
    :toTable()
-- { "Ada", "Bryn", "Cato" }

See also

SortBy · ThenByDecending · Functions

Clone this wiki locally