mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-14 12:15:05 +00:00
feat: Util methods for inserting items into a sorted list by a predicate
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ICD.Common.Properties;
|
||||
using ICD.Common.Utils.Comparers;
|
||||
|
||||
namespace ICD.Common.Utils.Extensions
|
||||
{
|
||||
@@ -50,6 +51,30 @@ namespace ICD.Common.Utils.Extensions
|
||||
items.ForEach(i => extends.AddSorted(i, comparer));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the items into a sorted list.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="TProp"></typeparam>
|
||||
/// <param name="extends"></param>
|
||||
/// <param name="items"></param>
|
||||
/// <param name="predicate"></param>
|
||||
[PublicAPI]
|
||||
public static void AddSorted<T, TProp>(this List<T> extends, IEnumerable<T> items, Func<T, TProp> predicate)
|
||||
{
|
||||
if (extends == null)
|
||||
throw new ArgumentNullException("extends");
|
||||
|
||||
if (items == null)
|
||||
throw new ArgumentNullException("items");
|
||||
|
||||
if (predicate == null)
|
||||
throw new ArgumentNullException("predicate");
|
||||
|
||||
PredicateComparer<T, TProp> comparer = new PredicateComparer<T, TProp>(predicate);
|
||||
extends.AddSorted(items, comparer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the item into a sorted list.
|
||||
/// </summary>
|
||||
@@ -106,6 +131,27 @@ namespace ICD.Common.Utils.Extensions
|
||||
extends.Insert(index, item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the item into a sorted list.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="TProp"></typeparam>
|
||||
/// <param name="extends"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="predicate"></param>
|
||||
[PublicAPI]
|
||||
public static void AddSorted<T, TProp>(this List<T> extends, T item, Func<T, TProp> predicate)
|
||||
{
|
||||
if (extends == null)
|
||||
throw new ArgumentNullException("extends");
|
||||
|
||||
if (predicate == null)
|
||||
throw new ArgumentNullException("predicate");
|
||||
|
||||
PredicateComparer<T, TProp> comparer = new PredicateComparer<T, TProp>(predicate);
|
||||
extends.AddSorted(item, comparer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pads the list to the given total length.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user