namespace PkmnLib.Static.Utils;
///
/// Extension methods for .
///
public static class EnumerableHelpers
{
///
/// Returns all elements of the enumerable that are not null.
///
public static IEnumerable WhereNotNull(this IEnumerable enumerable) where T : class =>
enumerable.Where(x => x is not null)!;
///
/// Finds the index of a value in an enumerable. Returns -1 if the value is not found.
///
public static int IndexOf(this IEnumerable enumerable, T value)
{
var index = 0;
foreach (var item in enumerable)
{
if (item is null)
{
if (value is null)
return index;
continue;
}
if (item.Equals(value))
return index;
index++;
}
return -1;
}
///
/// Removes all elements from a list that match the given predicate.
///
public static void RemoveAll(this IList list, Func predicate)
{
for (var i = list.Count - 1; i >= 0; i--)
{
if (predicate(list[i]))
list.RemoveAt(i);
}
}
}