Skip to content

Does not define the type of array element #1279

@RomanSpector

Description

@RomanSpector
---@class LinQ: tablelib

---@return LinQ
function LinQ() end

---@generic T, K, V
---@param tbl T|table<K, V>
---@param query? fun(a: V): boolean
---@return T
function table.whereList(tbl, query) end

---@param tbl table
---@return boolean
function table.isEmpty(tbl) end

---@type integer[]|LinQ
local intArray = LinQ {};

for i = 1, 10 do
    intArray:insert(math.random(1, 10));
end

---now the array is either empty or filled with ones and\or twos
local list = intArray:whereList(function(element)
    return element == 1 or element == 2
end)

---we make sure that there is something in the array and sort it
if not list:isEmpty() then
    list:sort(function(a, b) return a > b end)
    ---after sorting, there should be the maximum number from the array
    local firstEl = list[1];
end

image

Maybe I'm doing something wrong, if that's the case, tell me how it should be.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions