瀏覽代碼

More async variants for Min and Max.

Bart De Smet 8 年之前
父節點
當前提交
4f3598df20
共有 2 個文件被更改,包括 42 次插入0 次删除
  1. 21 0
      Ix.NET/Source/System.Interactive.Async/Max.cs
  2. 21 0
      Ix.NET/Source/System.Interactive.Async/Min.cs

+ 21 - 0
Ix.NET/Source/System.Interactive.Async/Max.cs

@@ -68,6 +68,27 @@ namespace System.Linq
                          .Max(cancellationToken);
         }
 
+        public static Task<TResult> Max<TSource, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<TResult>> selector)
+        {
+            if (source == null)
+                throw new ArgumentNullException(nameof(source));
+            if (selector == null)
+                throw new ArgumentNullException(nameof(selector));
+
+            return Max(source, selector, CancellationToken.None);
+        }
+
+        public static Task<TResult> Max<TSource, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<TResult>> 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<IList<TSource>> MaxBy<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector)
         {
             if (source == null)

+ 21 - 0
Ix.NET/Source/System.Interactive.Async/Min.cs

@@ -68,6 +68,27 @@ namespace System.Linq
                          .Min(cancellationToken);
         }
 
+        public static Task<TResult> Min<TSource, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<TResult>> selector)
+        {
+            if (source == null)
+                throw new ArgumentNullException(nameof(source));
+            if (selector == null)
+                throw new ArgumentNullException(nameof(selector));
+
+            return Min(source, selector, CancellationToken.None);
+        }
+
+        public static Task<TResult> Min<TSource, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<TResult>> 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<IList<TSource>> MinBy<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector)
         {
             if (source == null)