Unstable 0.14.5.0

This commit is contained in:
Markus Isberg
2021-06-14 17:53:42 +03:00
parent 1f3e588fcd
commit 23a7c37eee
25 changed files with 254 additions and 259 deletions
@@ -154,5 +154,22 @@ namespace Barotrauma.Extensions
{
if (value != null) { source.Add(value); }
}
/// <summary>
/// Returns whether a given collection has at least a certain amount
/// of elements for which the predicate returns true.
/// </summary>
/// <param name="source">Input collection</param>
/// <param name="amount">How many elements to match before stopping</param>
/// <param name="predicate">Predicate used to evaluate the elements</param>
public static bool AtLeast<T>(this IEnumerable<T> source, int amount, Predicate<T> predicate)
{
foreach (T elem in source)
{
if (predicate(elem)) { amount--; }
if (amount <= 0) { return true; }
}
return false;
}
}
}