Skip to content
This repository has been archived by the owner on Jul 28, 2022. It is now read-only.

Commit

Permalink
Added FastRemoveFirstValue function
Browse files Browse the repository at this point in the history
  • Loading branch information
Sleitnick committed Nov 25, 2018
1 parent e32ff63 commit 2fbfd57
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/ReplicatedStorage/Aero/Shared/TableUtil.modulescript.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
TableUtil.Sync(Table tbl, Table templateTbl)
TableUtil.Print(Table tbl, String label, Boolean deepPrint)
TableUtil.FastRemove(Table tbl, Number index)
TableUtil.FastRemoveFirstValue(Table tbl, Variant value)
TableUtil.Map(Table tbl, Function callback)
TableUtil.Filter(Table tbl, Function callback)
TableUtil.Reduce(Table tbl, Function callback [, Number initialValue])
Expand Down Expand Up @@ -61,6 +62,20 @@
print(table.concat(tbl, " ")) -- > hello this is a test
FastRemoveFirstValue:
Calls FastRemove on the first index that holds the given value.
local tbl = {"abc", "hello", "hi", "goodbye", "hello", "hey"}
local removed, atIndex = TableUtil.FastRemoveFirstValue(tbl, "hello")
if (removed) then
print("Removed at index " .. atIndex)
print(table.concat(tbl, " ")) -- > abc hi goodbye hello hey
else
print("Did not find value")
end
Map:
This allows you to construct a new table by calling the given function
Expand Down Expand Up @@ -354,9 +369,20 @@ local function DecodeJSON(str)
end


local function FastRemoveFirstValue(t, v)
local index = IndexOf(t, v)
if (index) then
FastRemove(t, index)
return true, index
end
return false, nil
end


TableUtil.Copy = CopyTable
TableUtil.Sync = Sync
TableUtil.FastRemove = FastRemove
TableUtil.FastRemoveFirstValue = FastRemoveFirstValue
TableUtil.Print = Print
TableUtil.Map = Map
TableUtil.Filter = Filter
Expand Down

0 comments on commit 2fbfd57

Please sign in to comment.