Skip to content

ThenByDecending

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

Enumerable:thenByDecending

Adds a descending sort criterion after the criteria of a previous sort.

Syntax

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

Parameters

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

Returns

The sorted Enumerable, with the additional criterion appended.

Remarks

The method is spelled thenByDecending in the current API. Call it on an Enumerable returned by a sort method or another chained sort criterion.

Example

local players = {
    { name = "Ada", role = "mage", damage = 1200 },
    { name = "Cato", role = "mage", damage = 950 },
    { name = "Bryn", role = "ranger", damage = 870 },
}

local ordered = LuaQ.from(players)
    :sortBy(function(player) return player.role end)
    :thenByDecending(function(player) return player.damage end)
    :map(function(player) return player.name end)
    :toTable()
-- Orders roles ascending, then damage descending

See also

SortBy · ThenBy · Functions

Clone this wiki locally