mirror of
https://github.com/TangentFoxy/lume.git
synced 2024-11-19 07:04:24 +00:00
Exposed internal isarray()
function as lume.isarray()
This commit is contained in:
parent
a20a39c8ee
commit
f226cf2e64
15
lume.lua
15
lume.lua
@ -40,12 +40,8 @@ local iscallable = function(x)
|
||||
return mt and mt.__call ~= nil
|
||||
end
|
||||
|
||||
local isarray = function(x)
|
||||
return (type(x) == "table" and x[1] ~= nil) and true or false
|
||||
end
|
||||
|
||||
local getiter = function(x)
|
||||
if isarray(x) then
|
||||
if lume.isarray(x) then
|
||||
return ipairs
|
||||
elseif type(x) == "table" then
|
||||
return pairs
|
||||
@ -142,6 +138,11 @@ function lume.weightedchoice(t)
|
||||
end
|
||||
|
||||
|
||||
function lume.isarray(x)
|
||||
return (type(x) == "table" and x[1] ~= nil) and true or false
|
||||
end
|
||||
|
||||
|
||||
function lume.push(t, ...)
|
||||
local n = select("#", ...)
|
||||
for i = 1, n do
|
||||
@ -155,7 +156,7 @@ function lume.remove(t, x)
|
||||
local iter = getiter(t)
|
||||
for i, v in iter(t) do
|
||||
if v == x then
|
||||
if isarray(t) then
|
||||
if lume.isarray(t) then
|
||||
table.remove(t, i)
|
||||
break
|
||||
else
|
||||
@ -381,7 +382,7 @@ function lume.count(t, fn)
|
||||
if fn(v) then count = count + 1 end
|
||||
end
|
||||
else
|
||||
if isarray(t) then
|
||||
if lume.isarray(t) then
|
||||
return #t
|
||||
end
|
||||
for _ in iter(t) do count = count + 1 end
|
||||
|
Loading…
Reference in New Issue
Block a user