public static TAccumulator Sum <T, TAccumulator, TSummator>(this T[] array, Additive <TAccumulator, T, TSummator> initial) where TSummator : struct, ISummator <TAccumulator, T> { var result = initial; for (var i = 0; i < array.Length; i++) { result += array[i]; } return(result); }
public static T Sum <T, TSummator, TEnumerable, TEnumerator>( this Enumerable <T, TEnumerator, TEnumerable> enumerable, Additive <T, TSummator> initial) where TEnumerator : IEnumerator <T> where TEnumerable : IEnumerable <T, TEnumerator> where TSummator : struct, ISummator <T> { var result = initial; foreach (var i in enumerable) { result += i; } return(result); }