diff --git a/src/DynamicData/Aggregation/CountEx.cs b/src/DynamicData/Aggregation/CountEx.cs index 83c4dd85..2f437657 100644 --- a/src/DynamicData/Aggregation/CountEx.cs +++ b/src/DynamicData/Aggregation/CountEx.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for full license information. using System; +using System.Reactive.Linq; namespace DynamicData.Aggregation { @@ -57,5 +58,67 @@ public static IObservable Count(this IObservable + /// Counts the total number of items in the underlying data source + /// and return true if the number of items == 0 + /// + /// The type of the object. + /// The type of the key. + /// The source. + /// + public static IObservable IsEmpty(this IObservable> source) + { + return source.ForAggregation() + .Count() + .StartWith(0) + .Select(count => count == 0); + } + + /// + /// Counts the total number of items in the underlying data source + /// and returns true if the number of items is greater than 0 + /// + /// The type of the object. + /// The type of the key. + /// The source. + /// + public static IObservable NotEmpty(this IObservable> source) + { + return source.ForAggregation() + .Count() + .StartWith(0) + .Select(count => count > 0); + } + + /// + /// Counts the total number of items in the underlying data source + /// and return true if the number of items == 0 + /// + /// The type of the object. + /// The source. + /// + public static IObservable IsEmpty(this IObservable> source) + { + return source.ForAggregation() + .Count() + .StartWith(0) + .Select(count => count == 0); + } + + /// + /// Counts the total number of items in the underlying data source + /// and returns true if the number of items is greater than 0 + /// + /// The type of the object. + /// The source. + /// + public static IObservable NotEmpty(this IObservable> source) + { + return source.ForAggregation() + .Count() + .StartWith(0) + .Select(count => count > 0); + } } }