Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not define the type of array element #1279

Closed
RomanSpector opened this issue Jul 4, 2022 · 0 comments
Closed

Does not define the type of array element #1279

RomanSpector opened this issue Jul 4, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@RomanSpector
Copy link

---@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.

@sumneko sumneko added the bug Something isn't working label Jul 5, 2022
@sumneko sumneko closed this as completed in c0ee6e9 Jul 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants