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
|
return mt and mt.__call ~= nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local isarray = function(x)
|
|
||||||
return (type(x) == "table" and x[1] ~= nil) and true or false
|
|
||||||
end
|
|
||||||
|
|
||||||
local getiter = function(x)
|
local getiter = function(x)
|
||||||
if isarray(x) then
|
if lume.isarray(x) then
|
||||||
return ipairs
|
return ipairs
|
||||||
elseif type(x) == "table" then
|
elseif type(x) == "table" then
|
||||||
return pairs
|
return pairs
|
||||||
@ -142,6 +138,11 @@ function lume.weightedchoice(t)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function lume.isarray(x)
|
||||||
|
return (type(x) == "table" and x[1] ~= nil) and true or false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function lume.push(t, ...)
|
function lume.push(t, ...)
|
||||||
local n = select("#", ...)
|
local n = select("#", ...)
|
||||||
for i = 1, n do
|
for i = 1, n do
|
||||||
@ -155,7 +156,7 @@ function lume.remove(t, x)
|
|||||||
local iter = getiter(t)
|
local iter = getiter(t)
|
||||||
for i, v in iter(t) do
|
for i, v in iter(t) do
|
||||||
if v == x then
|
if v == x then
|
||||||
if isarray(t) then
|
if lume.isarray(t) then
|
||||||
table.remove(t, i)
|
table.remove(t, i)
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
@ -381,7 +382,7 @@ function lume.count(t, fn)
|
|||||||
if fn(v) then count = count + 1 end
|
if fn(v) then count = count + 1 end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if isarray(t) then
|
if lume.isarray(t) then
|
||||||
return #t
|
return #t
|
||||||
end
|
end
|
||||||
for _ in iter(t) do count = count + 1 end
|
for _ in iter(t) do count = count + 1 end
|
||||||
|
Loading…
Reference in New Issue
Block a user