mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-22 22:24:35 +00:00
[modified] table.push and table.unshift return the table for possible chaining
This commit is contained in:
parent
b570ea7096
commit
7922cd3912
10
tablex.lua
10
tablex.lua
@ -28,9 +28,10 @@ function tablex.pop(t)
|
|||||||
return table.remove(t)
|
return table.remove(t)
|
||||||
end
|
end
|
||||||
|
|
||||||
--insert to the back of a table
|
--insert to the back of a table, returning the table for possible chaining
|
||||||
function tablex.push(t, v)
|
function tablex.push(t, v)
|
||||||
return table.insert(t, v)
|
table.insert(t, v)
|
||||||
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
--remove the front element of a table and return it
|
--remove the front element of a table and return it
|
||||||
@ -38,9 +39,10 @@ function tablex.shift(t)
|
|||||||
return table.remove(t, 1)
|
return table.remove(t, 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
--insert to the front of a table
|
--insert to the front of a table, returning the table for possible chaining
|
||||||
function tablex.unshift(t, v)
|
function tablex.unshift(t, v)
|
||||||
return table.insert(t, 1, v)
|
table.insert(t, 1, v)
|
||||||
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
--find the index in a sequential table that a resides at
|
--find the index in a sequential table that a resides at
|
||||||
|
Loading…
Reference in New Issue
Block a user