Skip to content

Commit

Permalink
feat: SyncList.FindIndex added (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
miwarnec authored and paulpach committed Apr 17, 2019
1 parent 2327498 commit b5ff43a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Assets/Mirror/Runtime/SyncList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,14 @@ public void Clear()

public int IndexOf(T item) => objects.IndexOf(item);

public int FindIndex(Predicate<T> match)
{
for (int i = 0; i < objects.Count; ++i)
if (match(objects[i]))
return i;
return -1;
}

public void Insert(int index, T item)
{
objects.Insert(index, item);
Expand Down
7 changes: 7 additions & 0 deletions Assets/Mirror/Tests/SyncListTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ public void TestRemove()
Assert.That(clientSyncList, Is.EquivalentTo(new[] { "Hello", "!" }));
}

[Test]
public void TestFindIndex()
{
int index = serverSyncList.FindIndex(entry => entry == "World");
Assert.That(index, Is.EqualTo(1));
}

[Test]
public void TestMultSync()
{
Expand Down

0 comments on commit b5ff43a

Please sign in to comment.