v0.14.6.0
This commit is contained in:
@@ -86,10 +86,11 @@ namespace Barotrauma.Extensions
|
||||
|
||||
/// <summary>
|
||||
/// Executes an action that modifies the collection on each element (such as removing items from the list).
|
||||
/// Creates a temporary list.
|
||||
/// Creates a temporary list, unless the collection is empty.
|
||||
/// </summary>
|
||||
public static void ForEachMod<T>(this IEnumerable<T> source, Action<T> action)
|
||||
{
|
||||
if (source.None()) { return; }
|
||||
var temp = new List<T>(source);
|
||||
temp.ForEach(action);
|
||||
}
|
||||
@@ -153,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user