Call as
Functions.collections.keys(array)
Record it as a dependency named Functions.collections.keys (accepting the completion does this), then call it by that name.
What it does
Collect table keys and sort them by their associated values using Lua less-than comparison. This sorts values rather than key names; equal values have no guaranteed key order.
Arguments
| Name | Type | What it does |
|---|---|---|
array | table | Table whose values must be mutually comparable. |
Returns
| 1 | table | Dense array of keys sorted by associated value. |
|---|
Editions
Built In helpers are registered on every edition. What differs is the game API they read; where one is missing the helper falls back or returns nil with a reason.
It reads no game API directly.
How the addon calls it
- Unit Classification (widget)
class:SetList(addon.classifications, Functions.collections.keys(addon.classifications)) - Combat Action History (widget)
action:SetList(addon.actions, Functions.collections.keys(addon.actions)) - Combat Action History Time (widget)
action:SetList(addon.actions, Functions.collections.keys(addon.actions)) - Creature Type (widget)
class:SetList(addon.creatures, Functions.collections.keys(addon.creatures)) - Debuff Type Present (widget)
debufftype:SetList(addon.debufftypes, Functions.collections.keys(addon.debufftypes)) - Extended Character Stat (widget)
stat:SetList(ecs_state.stats, Functions.collections.keys(ecs_state.stats)) - Extended Character Stat Percentage (widget)
stat:SetList(ecs_state.percentages, Functions.collections.keys(ecs_state.percentages)) - In Group (widget)
unit.configure=function() unit:SetList(units,Functions.collections.keys(units));unit:SetValue(value.unit or "player") end
and 9 more: Instance (widget), Health Within Range (widget), Health Percentage Within Range (widget), Mana Within Range (widget), Mana Percentage Within Range (widget), Role (widget), Totem Present (widget), Totem Time Remaining (widget), Zone PVP (widget)
Source
Functions/collections.lua, line 21. Read only in game; Duplicate makes an editable copy.
Functions.collections.keys(array)
local rv = {}
for k,_ in pairs(array) do
table.insert(rv, k)
end
-- Sort the keys
table.sort(rv, function (lhs, rhs) return array[lhs] < array[rhs] end)
return rv