Exemplo n.º 1
0
        /// <summary>
        /// Continual computes the sum of values matching the value selector.
        /// </summary>
        /// <typeparam name="T">The type of the item.</typeparam>
        /// <param name="source">The source.</param>
        /// <param name="valueSelector">The value selector.</param>
        /// <returns>An observable which emits the summed value.</returns>
        public static IObservable <decimal> Sum <T>(this IObservable <IAggregateChangeSet <T> > source, Func <T, decimal> valueSelector)
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (valueSelector is null)
            {
                throw new ArgumentNullException(nameof(valueSelector));
            }

            return(source.Accumulate(0, valueSelector, (current, value) => current + value, (current, value) => current - value));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Continual computes the sum of values matching the value selector.
        /// </summary>
        /// <typeparam name="T">The type of the item.</typeparam>
        /// <param name="source">The source.</param>
        /// <param name="valueSelector">The value selector.</param>
        /// <returns>An observable which emits the summed value.</returns>
        public static IObservable <float> Sum <T>(this IObservable <IAggregateChangeSet <T> > source, Func <T, float?> valueSelector)
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (valueSelector is null)
            {
                throw new ArgumentNullException(nameof(valueSelector));
            }

            return(source.Accumulate(0F, t => valueSelector(t).ValueOr(0), (current, value) => current + value, (current, value) => current - value));
        }
Exemplo n.º 3
0
 /// <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>An observable which emits the count.</returns>
 public static IObservable <int> Count <TObject>(this IObservable <IAggregateChangeSet <TObject> > source)
 {
     return(source.Accumulate(0, _ => 1, (current, increment) => current + increment, (current, increment) => current - increment));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Continual computes the sum of values matching the value selector.
 /// </summary>
 /// <typeparam name="T">The type of the item.</typeparam>
 /// <param name="source">The source.</param>
 /// <param name="valueSelector">The value selector.</param>
 /// <returns>An observable which emits the summed value.</returns>
 public static IObservable <int> Sum <T>(this IObservable <IAggregateChangeSet <T> > source, Func <T, int?> valueSelector)
 {
     return(source.Accumulate(0, t => valueSelector(t).GetValueOrDefault(), (current, value) => current + value, (current, value) => current - value));
 }