|
|
@@ -0,0 +1,757 @@
|
|
|
+// Licensed to the .NET Foundation under one or more agreements.
|
|
|
+// The .NET Foundation licenses this file to you under the Apache 2.0 License.
|
|
|
+// See the LICENSE file in the project root for more information.
|
|
|
+
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Threading;
|
|
|
+using System.Threading.Tasks;
|
|
|
+
|
|
|
+namespace System.Linq
|
|
|
+{
|
|
|
+ public static partial class AsyncEnumerable
|
|
|
+ {
|
|
|
+ public static Task<int> Max(this IAsyncEnumerable<int> source)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(Math.Max, CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<int> Max(this IAsyncEnumerable<int> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(Math.Max, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<int> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int> selector)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Max(CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<int> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Max(cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<long> Max(this IAsyncEnumerable<long> source)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(Math.Max, CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<long> Max(this IAsyncEnumerable<long> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(Math.Max, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<long> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long> selector)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Max(CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<long> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Max(cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<float> Max(this IAsyncEnumerable<float> source)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(Math.Max, CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<float> Max(this IAsyncEnumerable<float> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(Math.Max, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<float> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float> selector)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Max(CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<float> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Max(cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<double> Max(this IAsyncEnumerable<double> source)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(Math.Max, CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<double> Max(this IAsyncEnumerable<double> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(Math.Max, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<double> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double> selector)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Max(CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<double> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Max(cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<decimal> Max(this IAsyncEnumerable<decimal> source)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(Math.Max, CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<decimal> Max(this IAsyncEnumerable<decimal> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(Math.Max, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<decimal> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal> selector)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Max(CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<decimal> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Max(cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<int?> Max(this IAsyncEnumerable<int?> source)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(default(int?), NullableMax, CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<int?> Max(this IAsyncEnumerable<int?> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(default(int?), NullableMax, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<int?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int?> selector)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Max(CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<int?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int?> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Max(cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<long?> Max(this IAsyncEnumerable<long?> source)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(default(long?), NullableMax, CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<long?> Max(this IAsyncEnumerable<long?> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(default(long?), NullableMax, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<long?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long?> selector)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Max(CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<long?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long?> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Max(cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<float?> Max(this IAsyncEnumerable<float?> source)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(default(float?), NullableMax, CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<float?> Max(this IAsyncEnumerable<float?> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(default(float?), NullableMax, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<float?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float?> selector)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Max(CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<float?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float?> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Max(cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<double?> Max(this IAsyncEnumerable<double?> source)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(default(double?), NullableMax, CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<double?> Max(this IAsyncEnumerable<double?> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(default(double?), NullableMax, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<double?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double?> selector)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Max(CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<double?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double?> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Max(cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<decimal?> Max(this IAsyncEnumerable<decimal?> source)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(default(decimal?), NullableMax, CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<decimal?> Max(this IAsyncEnumerable<decimal?> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(default(decimal?), NullableMax, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<decimal?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal?> selector)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Max(CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<decimal?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal?> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Max(cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<int> Min(this IAsyncEnumerable<int> source)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(Math.Min, CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<int> Min(this IAsyncEnumerable<int> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(Math.Min, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<int> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int> selector)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Min(CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<int> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Min(cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<long> Min(this IAsyncEnumerable<long> source)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(Math.Min, CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<long> Min(this IAsyncEnumerable<long> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(Math.Min, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<long> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long> selector)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Min(CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<long> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Min(cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<float> Min(this IAsyncEnumerable<float> source)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(Math.Min, CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<float> Min(this IAsyncEnumerable<float> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(Math.Min, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<float> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float> selector)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Min(CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<float> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Min(cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<double> Min(this IAsyncEnumerable<double> source)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(Math.Min, CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<double> Min(this IAsyncEnumerable<double> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(Math.Min, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<double> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double> selector)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Min(CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<double> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Min(cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<decimal> Min(this IAsyncEnumerable<decimal> source)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(Math.Min, CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<decimal> Min(this IAsyncEnumerable<decimal> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(Math.Min, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<decimal> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal> selector)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Min(CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<decimal> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Min(cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<int?> Min(this IAsyncEnumerable<int?> source)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(default(int?), NullableMin, CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<int?> Min(this IAsyncEnumerable<int?> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(default(int?), NullableMin, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<int?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int?> selector)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Min(CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<int?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int?> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Min(cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<long?> Min(this IAsyncEnumerable<long?> source)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(default(long?), NullableMin, CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<long?> Min(this IAsyncEnumerable<long?> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(default(long?), NullableMin, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<long?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long?> selector)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Min(CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<long?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long?> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Min(cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<float?> Min(this IAsyncEnumerable<float?> source)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(default(float?), NullableMin, CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<float?> Min(this IAsyncEnumerable<float?> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(default(float?), NullableMin, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<float?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float?> selector)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Min(CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<float?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float?> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Min(cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<double?> Min(this IAsyncEnumerable<double?> source)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(default(double?), NullableMin, CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<double?> Min(this IAsyncEnumerable<double?> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(default(double?), NullableMin, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<double?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double?> selector)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Min(CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<double?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double?> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Min(cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<decimal?> Min(this IAsyncEnumerable<decimal?> source)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(default(decimal?), NullableMin, CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<decimal?> Min(this IAsyncEnumerable<decimal?> source, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+
|
|
|
+ return source.Aggregate(default(decimal?), NullableMin, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<decimal?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal?> selector)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Min(CancellationToken.None);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Task<decimal?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal?> selector, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (source == null)
|
|
|
+ throw new ArgumentNullException(nameof(source));
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException(nameof(selector));
|
|
|
+
|
|
|
+ return source.Select(selector).Min(cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static T? NullableMax<T>(T? x, T? y)
|
|
|
+ where T : struct, IComparable<T>
|
|
|
+ {
|
|
|
+ if (!x.HasValue)
|
|
|
+ return y;
|
|
|
+ if (!y.HasValue)
|
|
|
+ return x;
|
|
|
+ if (x.Value.CompareTo(y.Value) >= 0)
|
|
|
+ return x;
|
|
|
+ return y;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static T? NullableMin<T>(T? x, T? y)
|
|
|
+ where T : struct, IComparable<T>
|
|
|
+ {
|
|
|
+ if (!x.HasValue)
|
|
|
+ return y;
|
|
|
+ if (!y.HasValue)
|
|
|
+ return x;
|
|
|
+ if (x.Value.CompareTo(y.Value) <= 0)
|
|
|
+ return x;
|
|
|
+ return y;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|