From 5ffca5e7a3e0dc1c6edb3ff453e20dc4c66a726d Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Fri, 8 Nov 2019 14:57:27 -0500 Subject: [PATCH] feat: Adding overload for determining if a sorted list contains an item by a given predicate --- ICD.Common.Utils/Extensions/ListExtensions.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ICD.Common.Utils/Extensions/ListExtensions.cs b/ICD.Common.Utils/Extensions/ListExtensions.cs index e03b053..dd41884 100644 --- a/ICD.Common.Utils/Extensions/ListExtensions.cs +++ b/ICD.Common.Utils/Extensions/ListExtensions.cs @@ -323,6 +323,28 @@ namespace ICD.Common.Utils.Extensions return extends.BinarySearch(item, comparer) >= 0; } + /// + /// Returns true if the sorted list contains the given item. + /// + /// + /// + /// + /// + /// + [PublicAPI] + public static bool ContainsSorted([NotNull] this IList extends, T item, + [NotNull] Func predicate) + { + if (extends == null) + throw new ArgumentNullException("extends"); + + if (predicate == null) + throw new ArgumentNullException("predicate"); + + PredicateComparer comparer = new PredicateComparer(predicate); + return extends.ContainsSorted(item, comparer); + } + #endregion #region Binary Search