public static IEnumerable <double> PartialSums(this IEnumerable <double> self) { return(self.Accumulate(0.0, (x, y) => x + y)); }
public static IEnumerable <int> PartialSums(this IEnumerable <int> self) { return(self.Accumulate((x, y) => x + y)); }
/// <inheritdoc /> /// <summary> /// Calculate multiplication of elements in collection. /// </summary> /// <param name="source">Input collection.</param> /// <returns>Multiplication of elements in collection.</returns> public BigInteger Multiply( IEnumerable <int> source) => source.Accumulate( (accumulator, value) => accumulator * value, BigInteger.One);
public static IEnumerable <T> Accumulate <T>(this IEnumerable <T> self, Func <T, T, T> f) { return(self.Accumulate(default(T), f)); }
/// <inheritdoc /> /// <summary> /// Calculate sum of elements in collection. /// </summary> /// <param name="source">Input collection.</param> /// <returns>Sum of elements in collection.</returns> public BigInteger Sum( IEnumerable <int> source) => source.Accumulate( (accumulator, value) => accumulator + value, BigInteger.Zero);