aboutsummaryrefslogtreecommitdiff
path: root/configs/nvim/config-root/lua/crupest/utils/table.lua
blob: 22419b06f3be7e72b3c43500a3aa7117dbc09f81 (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
local function remove_element(tbl, element)
    local index = nil
    for i, v in ipairs(tbl) do
        if element == v then
            index = i
            break
        end
    end
    if index then
        table.remove(tbl, index)
    end
    return tbl
end

local function element_at(tbl, element)
    local at = nil
    for i, v in ipairs(tbl) do
        if element == v then
            at = i
            break
        end
    end
    return at
end

local function includes(tbl, element)
    for _, v in ipairs(tbl) do
        if v == element then return true end
    end
    return false
end

local function string_start_with(str, prefix)
    return string.find(str, prefix, 0, true) == 1
end

return {
    remove_element = remove_element,
    element_at = element_at,
    includes = includes,
    string_start_with = string_start_with,
}