Skip to content

Commit

Permalink
feat: Implement ITrackCollection#IndexOf
Browse files Browse the repository at this point in the history
  • Loading branch information
angelobreuer committed Sep 23, 2023
1 parent 7c32221 commit d8abd7a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Lavalink4NET/Players/Queued/ITrackCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public interface ITrackCollection : IReadOnlyList<ITrackQueueItem>

bool Contains(ITrackQueueItem item);

int IndexOf(ITrackQueueItem item);

int IndexOf(Func<ITrackQueueItem, bool> predicate);

ValueTask<bool> RemoveAtAsync(int index, CancellationToken cancellationToken = default);

ValueTask<bool> RemoveAsync(ITrackQueueItem item, CancellationToken cancellationToken = default);
Expand Down
23 changes: 23 additions & 0 deletions src/Lavalink4NET/Players/Queued/TrackCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,29 @@ public virtual void RemoveRange(int index, int count)
}

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

public virtual int IndexOf(ITrackQueueItem item)
{
ArgumentNullException.ThrowIfNull(item);
return Items.IndexOf(item);
}

public virtual int IndexOf(Func<ITrackQueueItem, bool> predicate)
{
ArgumentNullException.ThrowIfNull(predicate);

var items = Items;

for (var index = 0; index < items.Count; index++)
{
if (predicate(items[index]))
{
return index;
}
}

return -1;
}
}

file sealed class TrackEqualityComparer : IEqualityComparer<ITrackQueueItem>
Expand Down

0 comments on commit d8abd7a

Please sign in to comment.