浏览代码

Reduce code in Except, Intersect, and Union.

Bart De Smet 6 年之前
父节点
当前提交
05360aba29

+ 2 - 10
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Except.cs

@@ -4,22 +4,14 @@
 
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Threading;
 using System.Threading.Tasks;
 
 namespace System.Linq
 {
     public static partial class AsyncEnumerable
     {
-        public static IAsyncEnumerable<TSource> Except<TSource>(this IAsyncEnumerable<TSource> first, IAsyncEnumerable<TSource> second)
-        {
-            if (first == null)
-                throw Error.ArgumentNull(nameof(first));
-            if (second == null)
-                throw Error.ArgumentNull(nameof(second));
-
-            return new ExceptAsyncIterator<TSource>(first, second, comparer: null);
-        }
+        public static IAsyncEnumerable<TSource> Except<TSource>(this IAsyncEnumerable<TSource> first, IAsyncEnumerable<TSource> second) =>
+            Except(first, second, comparer: null);
 
         public static IAsyncEnumerable<TSource> Except<TSource>(this IAsyncEnumerable<TSource> first, IAsyncEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
         {

+ 2 - 10
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Intersect.cs

@@ -4,22 +4,14 @@
 
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Threading;
 using System.Threading.Tasks;
 
 namespace System.Linq
 {
     public static partial class AsyncEnumerable
     {
-        public static IAsyncEnumerable<TSource> Intersect<TSource>(this IAsyncEnumerable<TSource> first, IAsyncEnumerable<TSource> second)
-        {
-            if (first == null)
-                throw Error.ArgumentNull(nameof(first));
-            if (second == null)
-                throw Error.ArgumentNull(nameof(second));
-
-            return new IntersectAsyncIterator<TSource>(first, second, comparer: null);
-        }
+        public static IAsyncEnumerable<TSource> Intersect<TSource>(this IAsyncEnumerable<TSource> first, IAsyncEnumerable<TSource> second) =>
+            Intersect(first, second, comparer: null);
 
         public static IAsyncEnumerable<TSource> Intersect<TSource>(this IAsyncEnumerable<TSource> first, IAsyncEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
         {

+ 2 - 14
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Union.cs

@@ -11,15 +11,8 @@ namespace System.Linq
 {
     public static partial class AsyncEnumerable
     {
-        public static IAsyncEnumerable<TSource> Union<TSource>(this IAsyncEnumerable<TSource> first, IAsyncEnumerable<TSource> second)
-        {
-            if (first == null)
-                throw Error.ArgumentNull(nameof(first));
-            if (second == null)
-                throw Error.ArgumentNull(nameof(second));
-
-            return UnionCore(first, second, comparer: null);
-        }
+        public static IAsyncEnumerable<TSource> Union<TSource>(this IAsyncEnumerable<TSource> first, IAsyncEnumerable<TSource> second) =>
+            Union(first, second, comparer: null);
 
         public static IAsyncEnumerable<TSource> Union<TSource>(this IAsyncEnumerable<TSource> first, IAsyncEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
         {
@@ -28,11 +21,6 @@ namespace System.Linq
             if (second == null)
                 throw Error.ArgumentNull(nameof(second));
 
-            return UnionCore(first, second, comparer);
-        }
-
-        private static IAsyncEnumerable<TSource> UnionCore<TSource>(IAsyncEnumerable<TSource> first, IAsyncEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
-        {
             return first is UnionAsyncIterator<TSource> union && AreEqualityComparersEqual(comparer, union._comparer) ? union.Union(second) : new UnionAsyncIterator2<TSource>(first, second, comparer);
         }