Adding extension method for finding distinct items in a sequence based on a callback

This commit is contained in:
Chris Cameron
2018-02-12 14:32:36 -05:00
parent b6a1ce9bd2
commit 482424a714
3 changed files with 54 additions and 0 deletions

View File

@@ -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.