mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-13 11:44:57 +00:00
Adding extension method for finding distinct items in a sequence based on a callback
This commit is contained in:
@@ -643,6 +643,7 @@ namespace ICD.Common.Utils.Extensions
|
||||
/// <typeparam name="TValue"></typeparam>
|
||||
/// <param name="extends"></param>
|
||||
/// <returns></returns>
|
||||
[PublicAPI]
|
||||
public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> extends)
|
||||
{
|
||||
if (extends == null)
|
||||
@@ -651,6 +652,25 @@ namespace ICD.Common.Utils.Extensions
|
||||
return extends.ToDictionary(x => x.Key, x => x.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shim to
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="extends"></param>
|
||||
/// <param name="comparer"></param>
|
||||
/// <returns></returns>
|
||||
[PublicAPI]
|
||||
public static IEnumerable<T> Distinct<T>(this IEnumerable<T> extends, Func<T, T, bool> comparer)
|
||||
{
|
||||
if (extends == null)
|
||||
throw new ArgumentNullException("extends");
|
||||
|
||||
if (comparer == null)
|
||||
throw new ArgumentNullException("comparer");
|
||||
|
||||
return extends.Distinct(new FuncComparer<T>(comparer));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns other if the sequence is empty.
|
||||
/// Returns other if the sequence is non-empty and there are two different elements.
|
||||
|
||||
Reference in New Issue
Block a user