/// <summary> /// Continual computes the sum of values matching the value selector /// </summary> /// <typeparam name="T"></typeparam> /// <param name="source">The source.</param> /// <param name="valueSelector">The value selector.</param> /// <returns></returns> public static IObservable <int> Sum <T>([NotNull] this IObservable <IAggregateChangeSet <T> > source, [NotNull] Func <T, int?> valueSelector) { return(source.Accumlate(0, t => valueSelector(t).GetValueOrDefault(), (current, value) => current + value, (current, value) => current - value)); }
/// <summary> /// Continual computes the sum of values matching the value selector /// </summary> /// <typeparam name="T"></typeparam> /// <param name="source">The source.</param> /// <param name="valueSelector">The value selector.</param> /// <returns></returns> public static IObservable <float> Sum <T>([NotNull] this IObservable <IAggregateChangeSet <T> > source, [NotNull] Func <T, float?> valueSelector) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (valueSelector == null) { throw new ArgumentNullException(nameof(valueSelector)); } return(source.Accumlate(0F, t => valueSelector(t).ValueOr(0), (current, value) => current + value, (current, value) => current - value)); }
/// <summary> /// Counts the total number of items in the underlying data source /// </summary> /// <typeparam name="TObject">The type of the object.</typeparam> /// <param name="source">The source.</param> /// <returns></returns> public static IObservable <int> Count <TObject>(this IObservable <IAggregateChangeSet <TObject> > source) { return(source.Accumlate(0, t => 1, (current, increment) => current + increment, (current, increment) => current - increment)); }