summaryrefslogtreecommitdiffstats
path: root/lua/mason-core/functional/data.lua
blob: da6f1efd45e9827deb7c764c4547f023a14a2317 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
local _ = {}

_.table_pack = function(...)
    return { n = select("#", ...), ... }
end

---@generic T : string
---@param values T[]
---@return table<T, T>
_.enum = function(values)
    local result = {}
    for i = 1, #values do
        local v = values[i]
        result[v] = v
    end
    return result
end

---@generic T
---@param list T[]
---@return table<T, boolean>
_.set_of = function(list)
    local set = {}
    for i = 1, #list do
        set[list[i]] = true
    end
    return set
end

return _