private static TAccumulate Aggregate <TSource, TAccumulate>( this IEnumerator <TSource> iterator, TAccumulate accumulation, Func <TAccumulate, TSource, int, TAccumulate> func, int index) => iterator.MoveNext() ? iterator.Aggregate(func(accumulation, iterator.Current, index), func, checked (index + 1)) : accumulation;
public static TAccumulate Aggregate <TSource, TAccumulate>( this IEnumerable <TSource> source, TAccumulate seed, Func <TAccumulate, TSource, int, TAccumulate> func) { using (IEnumerator <TSource> iterator = source.GetEnumerator()) { return(iterator.Aggregate(seed, func, 0)); } }
public static TSource Aggregate <TSource>( this IEnumerable <TSource> source, Func <TSource, TSource, TSource> func) { using (IEnumerator <TSource> iterator = source.GetEnumerator()) { if (!iterator.MoveNext()) { throw new InvalidOperationException("Sequence contains no elements."); } return(iterator.Aggregate( iterator.Current, (accumulate, value, index) => func(accumulate, value), 1)); } }