|
@@ -15,7 +15,7 @@ namespace System.Linq
|
|
|
if (source == null)
|
|
|
throw new ArgumentNullException(nameof(source));
|
|
|
|
|
|
- return source.Aggregate(0, (x, y) => x + y, CancellationToken.None);
|
|
|
+ return SumCore(source, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<int> Sum(this IAsyncEnumerable<int> source, CancellationToken cancellationToken)
|
|
@@ -23,7 +23,7 @@ namespace System.Linq
|
|
|
if (source == null)
|
|
|
throw new ArgumentNullException(nameof(source));
|
|
|
|
|
|
- return source.Aggregate(0, (x, y) => x + y, cancellationToken);
|
|
|
+ return SumCore(source, cancellationToken);
|
|
|
}
|
|
|
|
|
|
public static Task<int> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int> selector)
|
|
@@ -33,7 +33,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(CancellationToken.None);
|
|
|
+ return SumCore(source, selector, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<int> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int> selector, CancellationToken cancellationToken)
|
|
@@ -43,7 +43,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(cancellationToken);
|
|
|
+ return SumCore(source, selector, cancellationToken);
|
|
|
}
|
|
|
|
|
|
public static Task<int> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<int>> selector)
|
|
@@ -53,7 +53,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(CancellationToken.None);
|
|
|
+ return SumCore(source, selector, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<int> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<int>> selector, CancellationToken cancellationToken)
|
|
@@ -63,15 +63,29 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
+ return SumCore(source, selector, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Task<int> SumCore(IAsyncEnumerable<int> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return source.Aggregate(0, (x, y) => x + y, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Task<int> SumCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, int> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
return source.Select(selector).Sum(cancellationToken);
|
|
|
}
|
|
|
|
|
|
+ private static Task<int> SumCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, Task<int>> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return source.Select(selector).Sum(cancellationToken);
|
|
|
+ }
|
|
|
public static Task<long> Sum(this IAsyncEnumerable<long> source)
|
|
|
{
|
|
|
if (source == null)
|
|
|
throw new ArgumentNullException(nameof(source));
|
|
|
|
|
|
- return source.Aggregate(0L, (x, y) => x + y, CancellationToken.None);
|
|
|
+ return SumCore(source, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<long> Sum(this IAsyncEnumerable<long> source, CancellationToken cancellationToken)
|
|
@@ -79,7 +93,7 @@ namespace System.Linq
|
|
|
if (source == null)
|
|
|
throw new ArgumentNullException(nameof(source));
|
|
|
|
|
|
- return source.Aggregate(0L, (x, y) => x + y, cancellationToken);
|
|
|
+ return SumCore(source, cancellationToken);
|
|
|
}
|
|
|
|
|
|
public static Task<long> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long> selector)
|
|
@@ -89,7 +103,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(CancellationToken.None);
|
|
|
+ return SumCore(source, selector, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<long> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long> selector, CancellationToken cancellationToken)
|
|
@@ -99,7 +113,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(cancellationToken);
|
|
|
+ return SumCore(source, selector, cancellationToken);
|
|
|
}
|
|
|
|
|
|
public static Task<long> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<long>> selector)
|
|
@@ -109,7 +123,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(CancellationToken.None);
|
|
|
+ return SumCore(source, selector, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<long> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<long>> selector, CancellationToken cancellationToken)
|
|
@@ -119,15 +133,29 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
+ return SumCore(source, selector, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Task<long> SumCore(IAsyncEnumerable<long> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return source.Aggregate(0L, (x, y) => x + y, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Task<long> SumCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, long> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
return source.Select(selector).Sum(cancellationToken);
|
|
|
}
|
|
|
|
|
|
+ private static Task<long> SumCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, Task<long>> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return source.Select(selector).Sum(cancellationToken);
|
|
|
+ }
|
|
|
public static Task<float> Sum(this IAsyncEnumerable<float> source)
|
|
|
{
|
|
|
if (source == null)
|
|
|
throw new ArgumentNullException(nameof(source));
|
|
|
|
|
|
- return source.Aggregate(0.0f, (x, y) => x + y, CancellationToken.None);
|
|
|
+ return SumCore(source, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<float> Sum(this IAsyncEnumerable<float> source, CancellationToken cancellationToken)
|
|
@@ -135,7 +163,7 @@ namespace System.Linq
|
|
|
if (source == null)
|
|
|
throw new ArgumentNullException(nameof(source));
|
|
|
|
|
|
- return source.Aggregate(0.0f, (x, y) => x + y, cancellationToken);
|
|
|
+ return SumCore(source, cancellationToken);
|
|
|
}
|
|
|
|
|
|
public static Task<float> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float> selector)
|
|
@@ -145,7 +173,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(CancellationToken.None);
|
|
|
+ return SumCore(source, selector, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<float> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float> selector, CancellationToken cancellationToken)
|
|
@@ -155,7 +183,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(cancellationToken);
|
|
|
+ return SumCore(source, selector, cancellationToken);
|
|
|
}
|
|
|
|
|
|
public static Task<float> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<float>> selector)
|
|
@@ -165,7 +193,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(CancellationToken.None);
|
|
|
+ return SumCore(source, selector, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<float> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<float>> selector, CancellationToken cancellationToken)
|
|
@@ -175,15 +203,29 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
+ return SumCore(source, selector, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Task<float> SumCore(IAsyncEnumerable<float> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return source.Aggregate(0.0f, (x, y) => x + y, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Task<float> SumCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, float> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
return source.Select(selector).Sum(cancellationToken);
|
|
|
}
|
|
|
|
|
|
+ private static Task<float> SumCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, Task<float>> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return source.Select(selector).Sum(cancellationToken);
|
|
|
+ }
|
|
|
public static Task<double> Sum(this IAsyncEnumerable<double> source)
|
|
|
{
|
|
|
if (source == null)
|
|
|
throw new ArgumentNullException(nameof(source));
|
|
|
|
|
|
- return source.Aggregate(0.0, (x, y) => x + y, CancellationToken.None);
|
|
|
+ return SumCore(source, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<double> Sum(this IAsyncEnumerable<double> source, CancellationToken cancellationToken)
|
|
@@ -191,7 +233,7 @@ namespace System.Linq
|
|
|
if (source == null)
|
|
|
throw new ArgumentNullException(nameof(source));
|
|
|
|
|
|
- return source.Aggregate(0.0, (x, y) => x + y, cancellationToken);
|
|
|
+ return SumCore(source, cancellationToken);
|
|
|
}
|
|
|
|
|
|
public static Task<double> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double> selector)
|
|
@@ -201,7 +243,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(CancellationToken.None);
|
|
|
+ return SumCore(source, selector, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<double> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double> selector, CancellationToken cancellationToken)
|
|
@@ -211,7 +253,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(cancellationToken);
|
|
|
+ return SumCore(source, selector, cancellationToken);
|
|
|
}
|
|
|
|
|
|
public static Task<double> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<double>> selector)
|
|
@@ -221,7 +263,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(CancellationToken.None);
|
|
|
+ return SumCore(source, selector, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<double> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<double>> selector, CancellationToken cancellationToken)
|
|
@@ -231,15 +273,29 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
+ return SumCore(source, selector, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Task<double> SumCore(IAsyncEnumerable<double> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return source.Aggregate(0.0, (x, y) => x + y, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Task<double> SumCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, double> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
return source.Select(selector).Sum(cancellationToken);
|
|
|
}
|
|
|
|
|
|
+ private static Task<double> SumCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, Task<double>> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return source.Select(selector).Sum(cancellationToken);
|
|
|
+ }
|
|
|
public static Task<decimal> Sum(this IAsyncEnumerable<decimal> source)
|
|
|
{
|
|
|
if (source == null)
|
|
|
throw new ArgumentNullException(nameof(source));
|
|
|
|
|
|
- return source.Aggregate(0m, (x, y) => x + y, CancellationToken.None);
|
|
|
+ return SumCore(source, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<decimal> Sum(this IAsyncEnumerable<decimal> source, CancellationToken cancellationToken)
|
|
@@ -247,7 +303,7 @@ namespace System.Linq
|
|
|
if (source == null)
|
|
|
throw new ArgumentNullException(nameof(source));
|
|
|
|
|
|
- return source.Aggregate(0m, (x, y) => x + y, cancellationToken);
|
|
|
+ return SumCore(source, cancellationToken);
|
|
|
}
|
|
|
|
|
|
public static Task<decimal> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal> selector)
|
|
@@ -257,7 +313,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(CancellationToken.None);
|
|
|
+ return SumCore(source, selector, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<decimal> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal> selector, CancellationToken cancellationToken)
|
|
@@ -267,7 +323,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(cancellationToken);
|
|
|
+ return SumCore(source, selector, cancellationToken);
|
|
|
}
|
|
|
|
|
|
public static Task<decimal> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<decimal>> selector)
|
|
@@ -277,7 +333,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(CancellationToken.None);
|
|
|
+ return SumCore(source, selector, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<decimal> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<decimal>> selector, CancellationToken cancellationToken)
|
|
@@ -287,15 +343,29 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
+ return SumCore(source, selector, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Task<decimal> SumCore(IAsyncEnumerable<decimal> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return source.Aggregate(0m, (x, y) => x + y, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Task<decimal> SumCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, decimal> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
return source.Select(selector).Sum(cancellationToken);
|
|
|
}
|
|
|
|
|
|
+ private static Task<decimal> SumCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, Task<decimal>> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return source.Select(selector).Sum(cancellationToken);
|
|
|
+ }
|
|
|
public static Task<int?> Sum(this IAsyncEnumerable<int?> source)
|
|
|
{
|
|
|
if (source == null)
|
|
|
throw new ArgumentNullException(nameof(source));
|
|
|
|
|
|
- return source.Aggregate((int?)0, (x, y) => x + y.GetValueOrDefault(), CancellationToken.None);
|
|
|
+ return SumCore(source, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<int?> Sum(this IAsyncEnumerable<int?> source, CancellationToken cancellationToken)
|
|
@@ -303,7 +373,7 @@ namespace System.Linq
|
|
|
if (source == null)
|
|
|
throw new ArgumentNullException(nameof(source));
|
|
|
|
|
|
- return source.Aggregate((int?)0, (x, y) => x + y.GetValueOrDefault(), cancellationToken);
|
|
|
+ return SumCore(source, cancellationToken);
|
|
|
}
|
|
|
|
|
|
public static Task<int?> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int?> selector)
|
|
@@ -313,7 +383,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(CancellationToken.None);
|
|
|
+ return SumCore(source, selector, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<int?> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int?> selector, CancellationToken cancellationToken)
|
|
@@ -323,7 +393,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(cancellationToken);
|
|
|
+ return SumCore(source, selector, cancellationToken);
|
|
|
}
|
|
|
|
|
|
public static Task<int?> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<int?>> selector)
|
|
@@ -333,7 +403,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(CancellationToken.None);
|
|
|
+ return SumCore(source, selector, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<int?> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<int?>> selector, CancellationToken cancellationToken)
|
|
@@ -343,15 +413,29 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
+ return SumCore(source, selector, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Task<int?> SumCore(IAsyncEnumerable<int?> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return source.Aggregate((int?)0, (x, y) => x + y.GetValueOrDefault(), cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Task<int?> SumCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, int?> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
return source.Select(selector).Sum(cancellationToken);
|
|
|
}
|
|
|
|
|
|
+ private static Task<int?> SumCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, Task<int?>> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return source.Select(selector).Sum(cancellationToken);
|
|
|
+ }
|
|
|
public static Task<long?> Sum(this IAsyncEnumerable<long?> source)
|
|
|
{
|
|
|
if (source == null)
|
|
|
throw new ArgumentNullException(nameof(source));
|
|
|
|
|
|
- return source.Aggregate((long?)0L, (x, y) => x + y.GetValueOrDefault(), CancellationToken.None);
|
|
|
+ return SumCore(source, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<long?> Sum(this IAsyncEnumerable<long?> source, CancellationToken cancellationToken)
|
|
@@ -359,7 +443,7 @@ namespace System.Linq
|
|
|
if (source == null)
|
|
|
throw new ArgumentNullException(nameof(source));
|
|
|
|
|
|
- return source.Aggregate((long?)0L, (x, y) => x + y.GetValueOrDefault(), cancellationToken);
|
|
|
+ return SumCore(source, cancellationToken);
|
|
|
}
|
|
|
|
|
|
public static Task<long?> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long?> selector)
|
|
@@ -369,7 +453,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(CancellationToken.None);
|
|
|
+ return SumCore(source, selector, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<long?> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long?> selector, CancellationToken cancellationToken)
|
|
@@ -379,7 +463,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(cancellationToken);
|
|
|
+ return SumCore(source, selector, cancellationToken);
|
|
|
}
|
|
|
|
|
|
public static Task<long?> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<long?>> selector)
|
|
@@ -389,7 +473,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(CancellationToken.None);
|
|
|
+ return SumCore(source, selector, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<long?> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<long?>> selector, CancellationToken cancellationToken)
|
|
@@ -399,15 +483,29 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
+ return SumCore(source, selector, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Task<long?> SumCore(IAsyncEnumerable<long?> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return source.Aggregate((long?)0L, (x, y) => x + y.GetValueOrDefault(), cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Task<long?> SumCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, long?> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
return source.Select(selector).Sum(cancellationToken);
|
|
|
}
|
|
|
|
|
|
+ private static Task<long?> SumCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, Task<long?>> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return source.Select(selector).Sum(cancellationToken);
|
|
|
+ }
|
|
|
public static Task<float?> Sum(this IAsyncEnumerable<float?> source)
|
|
|
{
|
|
|
if (source == null)
|
|
|
throw new ArgumentNullException(nameof(source));
|
|
|
|
|
|
- return source.Aggregate((float?)0.0f, (x, y) => x + y.GetValueOrDefault(), CancellationToken.None);
|
|
|
+ return SumCore(source, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<float?> Sum(this IAsyncEnumerable<float?> source, CancellationToken cancellationToken)
|
|
@@ -415,7 +513,7 @@ namespace System.Linq
|
|
|
if (source == null)
|
|
|
throw new ArgumentNullException(nameof(source));
|
|
|
|
|
|
- return source.Aggregate((float?)0.0f, (x, y) => x + y.GetValueOrDefault(), cancellationToken);
|
|
|
+ return SumCore(source, cancellationToken);
|
|
|
}
|
|
|
|
|
|
public static Task<float?> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float?> selector)
|
|
@@ -425,7 +523,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(CancellationToken.None);
|
|
|
+ return SumCore(source, selector, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<float?> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float?> selector, CancellationToken cancellationToken)
|
|
@@ -435,7 +533,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(cancellationToken);
|
|
|
+ return SumCore(source, selector, cancellationToken);
|
|
|
}
|
|
|
|
|
|
public static Task<float?> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<float?>> selector)
|
|
@@ -445,7 +543,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(CancellationToken.None);
|
|
|
+ return SumCore(source, selector, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<float?> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<float?>> selector, CancellationToken cancellationToken)
|
|
@@ -455,15 +553,29 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
+ return SumCore(source, selector, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Task<float?> SumCore(IAsyncEnumerable<float?> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return source.Aggregate((float?)0.0f, (x, y) => x + y.GetValueOrDefault(), cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Task<float?> SumCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, float?> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
return source.Select(selector).Sum(cancellationToken);
|
|
|
}
|
|
|
|
|
|
+ private static Task<float?> SumCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, Task<float?>> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return source.Select(selector).Sum(cancellationToken);
|
|
|
+ }
|
|
|
public static Task<double?> Sum(this IAsyncEnumerable<double?> source)
|
|
|
{
|
|
|
if (source == null)
|
|
|
throw new ArgumentNullException(nameof(source));
|
|
|
|
|
|
- return source.Aggregate((double?)0.0, (x, y) => x + y.GetValueOrDefault(), CancellationToken.None);
|
|
|
+ return SumCore(source, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<double?> Sum(this IAsyncEnumerable<double?> source, CancellationToken cancellationToken)
|
|
@@ -471,7 +583,7 @@ namespace System.Linq
|
|
|
if (source == null)
|
|
|
throw new ArgumentNullException(nameof(source));
|
|
|
|
|
|
- return source.Aggregate((double?)0.0, (x, y) => x + y.GetValueOrDefault(), cancellationToken);
|
|
|
+ return SumCore(source, cancellationToken);
|
|
|
}
|
|
|
|
|
|
public static Task<double?> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double?> selector)
|
|
@@ -481,7 +593,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(CancellationToken.None);
|
|
|
+ return SumCore(source, selector, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<double?> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double?> selector, CancellationToken cancellationToken)
|
|
@@ -491,7 +603,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(cancellationToken);
|
|
|
+ return SumCore(source, selector, cancellationToken);
|
|
|
}
|
|
|
|
|
|
public static Task<double?> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<double?>> selector)
|
|
@@ -501,7 +613,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(CancellationToken.None);
|
|
|
+ return SumCore(source, selector, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<double?> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<double?>> selector, CancellationToken cancellationToken)
|
|
@@ -511,15 +623,29 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
+ return SumCore(source, selector, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Task<double?> SumCore(IAsyncEnumerable<double?> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return source.Aggregate((double?)0.0, (x, y) => x + y.GetValueOrDefault(), cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Task<double?> SumCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, double?> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
return source.Select(selector).Sum(cancellationToken);
|
|
|
}
|
|
|
|
|
|
+ private static Task<double?> SumCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, Task<double?>> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return source.Select(selector).Sum(cancellationToken);
|
|
|
+ }
|
|
|
public static Task<decimal?> Sum(this IAsyncEnumerable<decimal?> source)
|
|
|
{
|
|
|
if (source == null)
|
|
|
throw new ArgumentNullException(nameof(source));
|
|
|
|
|
|
- return source.Aggregate((decimal?)0m, (x, y) => x + y.GetValueOrDefault(), CancellationToken.None);
|
|
|
+ return SumCore(source, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<decimal?> Sum(this IAsyncEnumerable<decimal?> source, CancellationToken cancellationToken)
|
|
@@ -527,7 +653,7 @@ namespace System.Linq
|
|
|
if (source == null)
|
|
|
throw new ArgumentNullException(nameof(source));
|
|
|
|
|
|
- return source.Aggregate((decimal?)0m, (x, y) => x + y.GetValueOrDefault(), cancellationToken);
|
|
|
+ return SumCore(source, cancellationToken);
|
|
|
}
|
|
|
|
|
|
public static Task<decimal?> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal?> selector)
|
|
@@ -537,7 +663,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(CancellationToken.None);
|
|
|
+ return SumCore(source, selector, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<decimal?> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal?> selector, CancellationToken cancellationToken)
|
|
@@ -547,7 +673,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(cancellationToken);
|
|
|
+ return SumCore(source, selector, cancellationToken);
|
|
|
}
|
|
|
|
|
|
public static Task<decimal?> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<decimal?>> selector)
|
|
@@ -557,7 +683,7 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
- return source.Select(selector).Sum(CancellationToken.None);
|
|
|
+ return SumCore(source, selector, CancellationToken.None);
|
|
|
}
|
|
|
|
|
|
public static Task<decimal?> Sum<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<decimal?>> selector, CancellationToken cancellationToken)
|
|
@@ -567,8 +693,22 @@ namespace System.Linq
|
|
|
if (selector == null)
|
|
|
throw new ArgumentNullException(nameof(selector));
|
|
|
|
|
|
+ return SumCore(source, selector, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Task<decimal?> SumCore(IAsyncEnumerable<decimal?> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return source.Aggregate((decimal?)0m, (x, y) => x + y.GetValueOrDefault(), cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Task<decimal?> SumCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, decimal?> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
return source.Select(selector).Sum(cancellationToken);
|
|
|
}
|
|
|
|
|
|
+ private static Task<decimal?> SumCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, Task<decimal?>> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return source.Select(selector).Sum(cancellationToken);
|
|
|
+ }
|
|
|
}
|
|
|
}
|