Browse Source

Enable nullable reference types.

Bart De Smet 6 years ago
parent
commit
f329683555
67 changed files with 612 additions and 574 deletions
  1. 1 1
      Ix.NET/Source/AsyncQueryableGenerator.t4
  2. 5 0
      Ix.NET/Source/System.Interactive.Async.Providers/System.Interactive.Async.Providers.csproj
  3. 15 15
      Ix.NET/Source/System.Interactive.Async.Providers/System/Linq/AsyncQueryableEx.Generated.cs
  4. 4 3
      Ix.NET/Source/System.Interactive.Async.Providers/System/Linq/AsyncQueryableEx.Generated.tt
  5. 1 0
      Ix.NET/Source/System.Interactive.Async/System.Interactive.Async.csproj
  6. 5 5
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Amb.cs
  7. 4 4
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Catch.cs
  8. 24 24
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Distinct.cs
  9. 19 11
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/DistinctUntilChanged.cs
  10. 3 3
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Do.cs
  11. 2 2
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Max.cs
  12. 6 6
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/MaxBy.cs
  13. 2 2
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Merge.cs
  14. 2 2
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Min.cs
  15. 5 5
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/MinBy.cs
  16. 3 5
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Never.cs
  17. 3 4
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/OnErrorResumeNext.cs
  18. 1 1
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Return.cs
  19. 1 1
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Throw.cs
  20. 3 3
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Timeout.cs
  21. 1 0
      Ix.NET/Source/System.Linq.Async.Queryable/System.Linq.Async.Queryable.csproj
  22. 1 1
      Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableExecutor.cs
  23. 3 4
      Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableQuery.cs
  24. 4 4
      Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableRewriter.cs
  25. 49 49
      Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncQueryable.Generated.cs
  26. 3 2
      Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncQueryable.Generated.tt
  27. 1 0
      Ix.NET/Source/System.Linq.Async/System.Linq.Async.csproj
  28. 1 1
      Ix.NET/Source/System.Linq.Async/System/Linq/AsyncEnumerableHelpers.cs
  29. 3 3
      Ix.NET/Source/System.Linq.Async/System/Linq/AsyncEnumerablePartition.cs
  30. 1 1
      Ix.NET/Source/System.Linq.Async/System/Linq/AsyncEnumerator.cs
  31. 2 2
      Ix.NET/Source/System.Linq.Async/System/Linq/AsyncIterator.cs
  32. 3 3
      Ix.NET/Source/System.Linq.Async/System/Linq/Disposables.cs
  33. 3 3
      Ix.NET/Source/System.Linq.Async/System/Linq/IOrderedAsyncEnumerable.cs
  34. 8 8
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/AppendPrepend.cs
  35. 6 6
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Concat.cs
  36. 1 1
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Contains.cs
  37. 3 3
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/DefaultIfEmpty.cs
  38. 7 7
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Distinct.cs
  39. 1 1
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ElementAtOrDefault.cs
  40. 1 1
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Empty.cs
  41. 1 1
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Except.cs
  42. 4 4
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/FirstOrDefault.cs
  43. 72 72
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/GroupBy.cs
  44. 3 3
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/GroupJoin.cs
  45. 9 1
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Grouping.cs
  46. 1 1
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Intersect.cs
  47. 6 6
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Join.cs
  48. 12 12
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/LastOrDefault.cs
  49. 121 105
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Lookup.cs
  50. 16 16
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Max.cs
  51. 16 16
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Min.cs
  52. 34 31
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/OrderedAsyncEnumerable.cs
  53. 2 2
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Reverse.cs
  54. 12 12
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Select.cs
  55. 12 12
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SelectMany.cs
  56. 1 1
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SequenceEqual.cs
  57. 5 5
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SingleLinkedNode.cs
  58. 9 9
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SingleOrDefault.cs
  59. 7 10
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToAsyncEnumerable.Observable.cs
  60. 6 6
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToAsyncEnumerable.cs
  61. 12 12
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToDictionary.cs
  62. 2 2
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToEnumerable.cs
  63. 2 2
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToHashSet.cs
  64. 12 12
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToLookup.cs
  65. 14 14
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Union.cs
  66. 8 8
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Where.cs
  67. 2 2
      Ix.NET/Source/System.Linq.Async/System/Linq/Set.cs

+ 1 - 1
Ix.NET/Source/AsyncQueryableGenerator.t4

@@ -154,7 +154,7 @@ foreach (var m in asyncEnumerableType.GetMethods()
         }
     }
 
-    var pars = string.Join(", ", m.GetParameters().Select((p, i) => (i == parCount - 1 && isParams ? "params " : "") + toQuoted(p.ParameterType, i) + " " + p.Name + (i == parCount - 1 && lastParameterDefault ? " = default" : "")));
+    var pars = string.Join(", ", m.GetParameters().Select((p, i) => (i == parCount - 1 && isParams ? "params " : "") + toQuoted(p.ParameterType, i) + (nullableParameterNames.Contains(p.Name) ? "?" : "") + " " + p.Name + (i == parCount - 1 && lastParameterDefault ? " = default" : "")));
     var quotedPars = string.Join(", ", m.GetParameters().Select((p, i) => "default(" + toQuoted(p.ParameterType, i) + ")"));
 
     if (m.IsDefined(typeof(System.Runtime.CompilerServices.ExtensionAttribute), true))

+ 5 - 0
Ix.NET/Source/System.Interactive.Async.Providers/System.Interactive.Async.Providers.csproj

@@ -5,6 +5,7 @@
     <AssemblyTitle>Interactive Extensions - Async Providers Library</AssemblyTitle>
     <TargetFrameworks>net461;netstandard2.0;netstandard2.1;netcoreapp3.0</TargetFrameworks>
     <PackageTags>Ix;Interactive;Extensions;Enumerable;Asynchronous</PackageTags>
+    <NullableContextOptions>enable</NullableContextOptions>
   </PropertyGroup>
 
   <ItemGroup>
@@ -21,4 +22,8 @@
     <Compile Update="System\Linq\AsyncQueryableEx.Generated.cs" DesignTime="True" AutoGen="True" DependentUpon="AsyncQueryableEx.Generated.tt" />
   </ItemGroup>
 
+  <ItemGroup>
+    <Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
+  </ItemGroup>
+
 </Project>

+ 15 - 15
Ix.NET/Source/System.Interactive.Async.Providers/System/Linq/AsyncQueryableEx.Generated.cs

@@ -188,7 +188,7 @@ namespace System.Linq
             (s_Distinct__TSource_TKey__3__0 ??
             (s_Distinct__TSource_TKey__3__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, CancellationToken, ValueTask<object>>>, IEqualityComparer<object>, IAsyncQueryable<object>>(Distinct<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static IAsyncQueryable<TSource> Distinct<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<TSource> Distinct<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, IEqualityComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -204,7 +204,7 @@ namespace System.Linq
             (s_Distinct__TSource_TKey__3__1 ??
             (s_Distinct__TSource_TKey__3__1 = new Func<IAsyncQueryable<object>, Expression<Func<object, object>>, IEqualityComparer<object>, IAsyncQueryable<object>>(Distinct<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static IAsyncQueryable<TSource> Distinct<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<TSource> Distinct<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IEqualityComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -220,7 +220,7 @@ namespace System.Linq
             (s_Distinct__TSource_TKey__3__2 ??
             (s_Distinct__TSource_TKey__3__2 = new Func<IAsyncQueryable<object>, Expression<Func<object, ValueTask<object>>>, IEqualityComparer<object>, IAsyncQueryable<object>>(Distinct<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static IAsyncQueryable<TSource> Distinct<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<TSource> Distinct<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, IEqualityComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -250,7 +250,7 @@ namespace System.Linq
             (s_DistinctUntilChanged__TSource__2__0 ??
             (s_DistinctUntilChanged__TSource__2__0 = new Func<IAsyncQueryable<object>, IEqualityComparer<object>, IAsyncQueryable<object>>(DistinctUntilChanged<object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource);
 
-        public static IAsyncQueryable<TSource> DistinctUntilChanged<TSource>(this IAsyncQueryable<TSource> source, IEqualityComparer<TSource> comparer)
+        public static IAsyncQueryable<TSource> DistinctUntilChanged<TSource>(this IAsyncQueryable<TSource> source, IEqualityComparer<TSource>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -312,7 +312,7 @@ namespace System.Linq
             (s_DistinctUntilChanged__TSource_TKey__3__0 ??
             (s_DistinctUntilChanged__TSource_TKey__3__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, CancellationToken, ValueTask<object>>>, IEqualityComparer<object>, IAsyncQueryable<object>>(DistinctUntilChanged<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static IAsyncQueryable<TSource> DistinctUntilChanged<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<TSource> DistinctUntilChanged<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, IEqualityComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -328,7 +328,7 @@ namespace System.Linq
             (s_DistinctUntilChanged__TSource_TKey__3__1 ??
             (s_DistinctUntilChanged__TSource_TKey__3__1 = new Func<IAsyncQueryable<object>, Expression<Func<object, object>>, IEqualityComparer<object>, IAsyncQueryable<object>>(DistinctUntilChanged<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static IAsyncQueryable<TSource> DistinctUntilChanged<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<TSource> DistinctUntilChanged<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IEqualityComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -344,7 +344,7 @@ namespace System.Linq
             (s_DistinctUntilChanged__TSource_TKey__3__2 ??
             (s_DistinctUntilChanged__TSource_TKey__3__2 = new Func<IAsyncQueryable<object>, Expression<Func<object, ValueTask<object>>>, IEqualityComparer<object>, IAsyncQueryable<object>>(DistinctUntilChanged<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static IAsyncQueryable<TSource> DistinctUntilChanged<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<TSource> DistinctUntilChanged<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, IEqualityComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -700,7 +700,7 @@ namespace System.Linq
             (s_MaxAsync__TSource__3__0 ??
             (s_MaxAsync__TSource__3__0 = new Func<IAsyncQueryable<object>, IComparer<object>, CancellationToken, ValueTask<object>>(MaxAsync<object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource);
 
-        public static ValueTask<TSource> MaxAsync<TSource>(this IAsyncQueryable<TSource> source, IComparer<TSource> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<TSource> MaxAsync<TSource>(this IAsyncQueryable<TSource> source, IComparer<TSource>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -762,7 +762,7 @@ namespace System.Linq
             (s_MaxByAsync__TSource_TKey__4__0 ??
             (s_MaxByAsync__TSource_TKey__4__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, CancellationToken, ValueTask<object>>>, IComparer<object>, CancellationToken, ValueTask<IList<object>>>(MaxByAsync<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static ValueTask<IList<TSource>> MaxByAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, IComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<IList<TSource>> MaxByAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, IComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -778,7 +778,7 @@ namespace System.Linq
             (s_MaxByAsync__TSource_TKey__4__1 ??
             (s_MaxByAsync__TSource_TKey__4__1 = new Func<IAsyncQueryable<object>, Expression<Func<object, object>>, IComparer<object>, CancellationToken, ValueTask<IList<object>>>(MaxByAsync<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static ValueTask<IList<TSource>> MaxByAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<IList<TSource>> MaxByAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -794,7 +794,7 @@ namespace System.Linq
             (s_MaxByAsync__TSource_TKey__4__2 ??
             (s_MaxByAsync__TSource_TKey__4__2 = new Func<IAsyncQueryable<object>, Expression<Func<object, ValueTask<object>>>, IComparer<object>, CancellationToken, ValueTask<IList<object>>>(MaxByAsync<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static ValueTask<IList<TSource>> MaxByAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, IComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<IList<TSource>> MaxByAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, IComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -824,7 +824,7 @@ namespace System.Linq
             (s_MinAsync__TSource__3__0 ??
             (s_MinAsync__TSource__3__0 = new Func<IAsyncQueryable<object>, IComparer<object>, CancellationToken, ValueTask<object>>(MinAsync<object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource);
 
-        public static ValueTask<TSource> MinAsync<TSource>(this IAsyncQueryable<TSource> source, IComparer<TSource> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<TSource> MinAsync<TSource>(this IAsyncQueryable<TSource> source, IComparer<TSource>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -886,7 +886,7 @@ namespace System.Linq
             (s_MinByAsync__TSource_TKey__4__0 ??
             (s_MinByAsync__TSource_TKey__4__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, CancellationToken, ValueTask<object>>>, IComparer<object>, CancellationToken, ValueTask<IList<object>>>(MinByAsync<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static ValueTask<IList<TSource>> MinByAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, IComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<IList<TSource>> MinByAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, IComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -902,7 +902,7 @@ namespace System.Linq
             (s_MinByAsync__TSource_TKey__4__1 ??
             (s_MinByAsync__TSource_TKey__4__1 = new Func<IAsyncQueryable<object>, Expression<Func<object, object>>, IComparer<object>, CancellationToken, ValueTask<IList<object>>>(MinByAsync<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static ValueTask<IList<TSource>> MinByAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<IList<TSource>> MinByAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -918,7 +918,7 @@ namespace System.Linq
             (s_MinByAsync__TSource_TKey__4__2 ??
             (s_MinByAsync__TSource_TKey__4__2 = new Func<IAsyncQueryable<object>, Expression<Func<object, ValueTask<object>>>, IComparer<object>, CancellationToken, ValueTask<IList<object>>>(MinByAsync<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static ValueTask<IList<TSource>> MinByAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, IComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<IList<TSource>> MinByAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, IComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));

+ 4 - 3
Ix.NET/Source/System.Interactive.Async.Providers/System/Linq/AsyncQueryableEx.Generated.tt

@@ -3,9 +3,10 @@
 // See the LICENSE file in the project root for more information. 
 
 <#@ template debug="false" hostspecific="false" language="C#" #>
-<#@ assembly name="$(ProjectDir)\..\System.Linq.Async\bin\$(Configuration)\net46\System.Threading.Tasks.Extensions.dll" #>
-<#@ assembly name="$(ProjectDir)\..\System.Linq.Async\bin\$(Configuration)\net46\System.Linq.Async.dll" #>
-<#@ assembly name="$(ProjectDir)\..\System.Interactive.Async\bin\$(Configuration)\net46\System.Interactive.Async.dll" #>
+<#@ assembly name="$(ProjectDir)\..\System.Linq.Async\bin\$(Configuration)\net461\Microsoft.Bcl.AsyncInterfaces.dll" #>
+<#@ assembly name="$(ProjectDir)\..\System.Linq.Async\bin\$(Configuration)\net461\System.Threading.Tasks.Extensions.dll" #>
+<#@ assembly name="$(ProjectDir)\..\System.Linq.Async\bin\$(Configuration)\net461\System.Linq.Async.dll" #>
+<#@ assembly name="$(ProjectDir)\..\System.Interactive.Async\bin\$(Configuration)\net461\System.Interactive.Async.dll" #>
 <#@ output extension=".cs" #>
 <#
 var asyncEnumerableType = typeof(AsyncEnumerableEx);

+ 1 - 0
Ix.NET/Source/System.Interactive.Async/System.Interactive.Async.csproj

@@ -5,6 +5,7 @@
     <AssemblyTitle>Interactive Extensions - Async Library</AssemblyTitle>
     <TargetFrameworks>net461;netstandard2.0;netstandard2.1;netcoreapp3.0</TargetFrameworks>
     <PackageTags>Ix;Interactive;Extensions;Enumerable;Asynchronous</PackageTags>
+    <NullableContextOptions>enable</NullableContextOptions>
   </PropertyGroup>
 
   <ItemGroup>

+ 5 - 5
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Amb.cs

@@ -21,11 +21,11 @@ namespace System.Linq
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
             {
-                IAsyncEnumerator<TSource> firstEnumerator = null;
-                IAsyncEnumerator<TSource> secondEnumerator = null;
+                IAsyncEnumerator<TSource>? firstEnumerator = null;
+                IAsyncEnumerator<TSource>? secondEnumerator = null;
 
-                Task<bool> firstMoveNext = null;
-                Task<bool> secondMoveNext = null;
+                Task<bool>? firstMoveNext = null;
+                Task<bool>? secondMoveNext = null;
 
                 try
                 {
@@ -228,7 +228,7 @@ namespace System.Linq
             return Amb(sources.ToArray());
         }
 
-        private static async Task AwaitMoveNextAsyncAndDispose<T>(Task<bool> moveNextAsync, IAsyncEnumerator<T> enumerator)
+        private static async Task AwaitMoveNextAsyncAndDispose<T>(Task<bool>? moveNextAsync, IAsyncEnumerator<T>? enumerator)
         {
             if (enumerator != null)
             {

+ 4 - 4
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Catch.cs

@@ -41,7 +41,7 @@ namespace System.Linq
                 {
                     while (true)
                     {
-                        var c = default(TSource);
+                        TSource c;
 
                         try
                         {
@@ -95,7 +95,7 @@ namespace System.Linq
                 {
                     while (true)
                     {
-                        var c = default(TSource);
+                        TSource c;
 
                         try
                         {
@@ -150,7 +150,7 @@ namespace System.Linq
                 {
                     while (true)
                     {
-                        var c = default(TSource);
+                        TSource c;
 
                         try
                         {
@@ -222,7 +222,7 @@ namespace System.Linq
 
                         while (true)
                         {
-                            var c = default(TSource);
+                            TSource c;
 
                             try
                             {

+ 24 - 24
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Distinct.cs

@@ -21,7 +21,7 @@ namespace System.Linq
             return DistinctCore(source, keySelector, comparer: null);
         }
 
-        public static IAsyncEnumerable<TSource> Distinct<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncEnumerable<TSource> Distinct<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -53,7 +53,7 @@ namespace System.Linq
         }
 #endif
 
-        public static IAsyncEnumerable<TSource> Distinct<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncEnumerable<TSource> Distinct<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -64,7 +64,7 @@ namespace System.Linq
         }
 
 #if !NO_DEEP_CANCELLATION
-        public static IAsyncEnumerable<TSource> Distinct<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncEnumerable<TSource> Distinct<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -75,18 +75,18 @@ namespace System.Linq
         }
 #endif
 
-        private static IAsyncEnumerable<TSource> DistinctCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
+        private static IAsyncEnumerable<TSource> DistinctCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer)
         {
             return new DistinctAsyncIterator<TSource, TKey>(source, keySelector, comparer);
         }
 
-        private static IAsyncEnumerable<TSource> DistinctCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer)
+        private static IAsyncEnumerable<TSource> DistinctCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer)
         {
             return new DistinctAsyncIteratorWithTask<TSource, TKey>(source, keySelector, comparer);
         }
 
 #if !NO_DEEP_CANCELLATION
-        private static IAsyncEnumerable<TSource> DistinctCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer)
+        private static IAsyncEnumerable<TSource> DistinctCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer)
         {
             return new DistinctAsyncIteratorWithTaskAndCancellation<TSource, TKey>(source, keySelector, comparer);
         }
@@ -94,14 +94,14 @@ namespace System.Linq
 
         private sealed class DistinctAsyncIterator<TSource, TKey> : AsyncIterator<TSource>, IAsyncIListProvider<TSource>
         {
-            private readonly IEqualityComparer<TKey> _comparer;
+            private readonly IEqualityComparer<TKey>? _comparer;
             private readonly Func<TSource, TKey> _keySelector;
             private readonly IAsyncEnumerable<TSource> _source;
 
-            private IAsyncEnumerator<TSource> _enumerator;
-            private Set<TKey> _set;
+            private IAsyncEnumerator<TSource>? _enumerator;
+            private Set<TKey>? _set;
 
-            public DistinctAsyncIterator(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
+            public DistinctAsyncIterator(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer)
             {
                 Debug.Assert(source != null);
                 Debug.Assert(keySelector != null);
@@ -194,11 +194,11 @@ namespace System.Linq
                         return true;
 
                     case AsyncIteratorState.Iterating:
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
+                        while (await _enumerator!.MoveNextAsync().ConfigureAwait(false))
                         {
                             element = _enumerator.Current;
 
-                            if (_set.Add(_keySelector(element)))
+                            if (_set!.Add(_keySelector(element)))
                             {
                                 _current = element;
                                 return true;
@@ -242,14 +242,14 @@ namespace System.Linq
 
         private sealed class DistinctAsyncIteratorWithTask<TSource, TKey> : AsyncIterator<TSource>, IAsyncIListProvider<TSource>
         {
-            private readonly IEqualityComparer<TKey> _comparer;
+            private readonly IEqualityComparer<TKey>? _comparer;
             private readonly Func<TSource, ValueTask<TKey>> _keySelector;
             private readonly IAsyncEnumerable<TSource> _source;
 
-            private IAsyncEnumerator<TSource> _enumerator;
-            private Set<TKey> _set;
+            private IAsyncEnumerator<TSource>? _enumerator;
+            private Set<TKey>? _set;
 
-            public DistinctAsyncIteratorWithTask(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer)
+            public DistinctAsyncIteratorWithTask(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer)
             {
                 Debug.Assert(source != null);
                 Debug.Assert(keySelector != null);
@@ -342,11 +342,11 @@ namespace System.Linq
                         return true;
 
                     case AsyncIteratorState.Iterating:
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
+                        while (await _enumerator!.MoveNextAsync().ConfigureAwait(false))
                         {
                             element = _enumerator.Current;
 
-                            if (_set.Add(await _keySelector(element).ConfigureAwait(false)))
+                            if (_set!.Add(await _keySelector(element).ConfigureAwait(false)))
                             {
                                 _current = element;
                                 return true;
@@ -391,14 +391,14 @@ namespace System.Linq
 #if !NO_DEEP_CANCELLATION
         private sealed class DistinctAsyncIteratorWithTaskAndCancellation<TSource, TKey> : AsyncIterator<TSource>, IAsyncIListProvider<TSource>
         {
-            private readonly IEqualityComparer<TKey> _comparer;
+            private readonly IEqualityComparer<TKey>? _comparer;
             private readonly Func<TSource, CancellationToken, ValueTask<TKey>> _keySelector;
             private readonly IAsyncEnumerable<TSource> _source;
 
-            private IAsyncEnumerator<TSource> _enumerator;
-            private Set<TKey> _set;
+            private IAsyncEnumerator<TSource>? _enumerator;
+            private Set<TKey>? _set;
 
-            public DistinctAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer)
+            public DistinctAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer)
             {
                 Debug.Assert(source != null);
                 Debug.Assert(keySelector != null);
@@ -491,11 +491,11 @@ namespace System.Linq
                         return true;
 
                     case AsyncIteratorState.Iterating:
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
+                        while (await _enumerator!.MoveNextAsync().ConfigureAwait(false))
                         {
                             element = _enumerator.Current;
 
-                            if (_set.Add(await _keySelector(element, _cancellationToken).ConfigureAwait(false)))
+                            if (_set!.Add(await _keySelector(element, _cancellationToken).ConfigureAwait(false)))
                             {
                                 _current = element;
                                 return true;

+ 19 - 11
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/DistinctUntilChanged.cs

@@ -18,7 +18,7 @@ namespace System.Linq
             return DistinctUntilChangedCore(source, comparer: null);
         }
 
-        public static IAsyncEnumerable<TSource> DistinctUntilChanged<TSource>(this IAsyncEnumerable<TSource> source, IEqualityComparer<TSource> comparer)
+        public static IAsyncEnumerable<TSource> DistinctUntilChanged<TSource>(this IAsyncEnumerable<TSource> source, IEqualityComparer<TSource>? comparer)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -36,7 +36,7 @@ namespace System.Linq
             return DistinctUntilChangedCore(source, keySelector, comparer: null);
         }
 
-        public static IAsyncEnumerable<TSource> DistinctUntilChanged<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncEnumerable<TSource> DistinctUntilChanged<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -68,7 +68,7 @@ namespace System.Linq
         }
 #endif
 
-        public static IAsyncEnumerable<TSource> DistinctUntilChanged<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncEnumerable<TSource> DistinctUntilChanged<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -90,7 +90,7 @@ namespace System.Linq
         }
 #endif
 
-        private static IAsyncEnumerable<TSource> DistinctUntilChangedCore<TSource>(IAsyncEnumerable<TSource> source, IEqualityComparer<TSource> comparer)
+        private static IAsyncEnumerable<TSource> DistinctUntilChangedCore<TSource>(IAsyncEnumerable<TSource> source, IEqualityComparer<TSource>? comparer)
         {
             comparer ??= EqualityComparer<TSource>.Default;
 
@@ -113,7 +113,9 @@ namespace System.Linq
                     {
                         var item = e.Current;
 
-                        if (!comparer.Equals(latest, item))
+                        // REVIEW: Need comparer!.Equals to satisfy nullable reference type warnings.
+
+                        if (!comparer!.Equals(latest, item))
                         {
                             latest = item;
 
@@ -124,7 +126,7 @@ namespace System.Linq
             }
         }
 
-        private static IAsyncEnumerable<TSource> DistinctUntilChangedCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
+        private static IAsyncEnumerable<TSource> DistinctUntilChangedCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer)
         {
             comparer ??= EqualityComparer<TKey>.Default;
 
@@ -151,7 +153,9 @@ namespace System.Linq
 
                         var currentKey = keySelector(item);
 
-                        if (!comparer.Equals(latestKey, currentKey))
+                        // REVIEW: Need comparer!.Equals to satisfy nullable reference type warnings.
+
+                        if (!comparer!.Equals(latestKey, currentKey))
                         {
                             latestKey = currentKey;
 
@@ -162,7 +166,7 @@ namespace System.Linq
             }
         }
 
-        private static IAsyncEnumerable<TSource> DistinctUntilChangedCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer)
+        private static IAsyncEnumerable<TSource> DistinctUntilChangedCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer)
         {
             comparer ??= EqualityComparer<TKey>.Default;
 
@@ -189,7 +193,9 @@ namespace System.Linq
 
                         var currentKey = await keySelector(item).ConfigureAwait(false);
 
-                        if (!comparer.Equals(latestKey, currentKey))
+                        // REVIEW: Need comparer!.Equals to satisfy nullable reference type warnings.
+
+                        if (!comparer!.Equals(latestKey, currentKey))
                         {
                             latestKey = currentKey;
 
@@ -201,7 +207,7 @@ namespace System.Linq
         }
 
 #if !NO_DEEP_CANCELLATION
-        private static IAsyncEnumerable<TSource> DistinctUntilChangedCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer)
+        private static IAsyncEnumerable<TSource> DistinctUntilChangedCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer)
         {
             comparer ??= EqualityComparer<TKey>.Default;
 
@@ -228,7 +234,9 @@ namespace System.Linq
 
                         var currentKey = await keySelector(item, cancellationToken).ConfigureAwait(false);
 
-                        if (!comparer.Equals(latestKey, currentKey))
+                        // REVIEW: Need comparer!.Equals to satisfy nullable reference type warnings.
+
+                        if (!comparer!.Equals(latestKey, currentKey))
                         {
                             latestKey = currentKey;
 

+ 3 - 3
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Do.cs

@@ -168,7 +168,7 @@ namespace System.Linq
             return DoCore(source, new Action<TSource>(observer.OnNext), new Action<Exception>(observer.OnError), new Action(observer.OnCompleted));
         }
 
-        private static IAsyncEnumerable<TSource> DoCore<TSource>(IAsyncEnumerable<TSource> source, Action<TSource> onNext, Action<Exception> onError, Action onCompleted)
+        private static IAsyncEnumerable<TSource> DoCore<TSource>(IAsyncEnumerable<TSource> source, Action<TSource> onNext, Action<Exception>? onError, Action? onCompleted)
         {
             return AsyncEnumerable.Create(Core);
 
@@ -209,7 +209,7 @@ namespace System.Linq
             }
         }
 
-        private static IAsyncEnumerable<TSource> DoCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, Task> onNext, Func<Exception, Task> onError, Func<Task> onCompleted)
+        private static IAsyncEnumerable<TSource> DoCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, Task> onNext, Func<Exception, Task>? onError, Func<Task>? onCompleted)
         {
             return AsyncEnumerable.Create(Core);
 
@@ -254,7 +254,7 @@ namespace System.Linq
         }
 
 #if !NO_DEEP_CANCELLATION
-        private static IAsyncEnumerable<TSource> DoCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, Task> onNext, Func<Exception, CancellationToken, Task> onError, Func<CancellationToken, Task> onCompleted)
+        private static IAsyncEnumerable<TSource> DoCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, Task> onNext, Func<Exception, CancellationToken, Task>? onError, Func<CancellationToken, Task>? onCompleted)
         {
             return AsyncEnumerable.Create(Core);
 

+ 2 - 2
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Max.cs

@@ -10,14 +10,14 @@ namespace System.Linq
 {
     public static partial class AsyncEnumerableEx
     {
-        public static ValueTask<TSource> MaxAsync<TSource>(this IAsyncEnumerable<TSource> source, IComparer<TSource> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<TSource> MaxAsync<TSource>(this IAsyncEnumerable<TSource> source, IComparer<TSource>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
 
             return Core(source, comparer, cancellationToken);
 
-            static async ValueTask<TSource> Core(IAsyncEnumerable<TSource> source, IComparer<TSource> comparer, CancellationToken cancellationToken)
+            static async ValueTask<TSource> Core(IAsyncEnumerable<TSource> source, IComparer<TSource>? comparer, CancellationToken cancellationToken)
             {
                 comparer ??= Comparer<TSource>.Default;
 

+ 6 - 6
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/MaxBy.cs

@@ -20,7 +20,7 @@ namespace System.Linq
             return MaxByCore(source, keySelector, comparer: null, cancellationToken);
         }
 
-        public static ValueTask<IList<TSource>> MaxByAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<IList<TSource>> MaxByAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -52,7 +52,7 @@ namespace System.Linq
         }
 #endif
 
-        public static ValueTask<IList<TSource>> MaxByAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<IList<TSource>> MaxByAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -63,7 +63,7 @@ namespace System.Linq
         }
 
 #if !NO_DEEP_CANCELLATION
-        public static ValueTask<IList<TSource>> MaxByAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<IList<TSource>> MaxByAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -74,14 +74,14 @@ namespace System.Linq
         }
 #endif
 
-        private static ValueTask<IList<TSource>> MaxByCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer, CancellationToken cancellationToken)
+        private static ValueTask<IList<TSource>> MaxByCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey>? comparer, CancellationToken cancellationToken)
         {
             comparer ??= Comparer<TKey>.Default;
 
             return ExtremaBy(source, keySelector, (key, minValue) => comparer.Compare(key, minValue), cancellationToken);
         }
 
-        private static ValueTask<IList<TSource>> MaxByCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IComparer<TKey> comparer, CancellationToken cancellationToken)
+        private static ValueTask<IList<TSource>> MaxByCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IComparer<TKey>? comparer, CancellationToken cancellationToken)
         {
             comparer ??= Comparer<TKey>.Default;
 
@@ -89,7 +89,7 @@ namespace System.Linq
         }
 
 #if !NO_DEEP_CANCELLATION
-        private static ValueTask<IList<TSource>> MaxByCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IComparer<TKey> comparer, CancellationToken cancellationToken)
+        private static ValueTask<IList<TSource>> MaxByCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IComparer<TKey>? comparer, CancellationToken cancellationToken)
         {
             comparer ??= Comparer<TKey>.Default;
 

+ 2 - 2
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Merge.cs

@@ -176,7 +176,7 @@ namespace System.Linq
             {
                 var count = sources.Length;
 
-                var enumerators = new IAsyncEnumerator<TSource>[count];
+                var enumerators = new IAsyncEnumerator<TSource>?[count];
                 var moveNextTasks = new Task<bool>[count];
 
                 try
@@ -212,7 +212,7 @@ namespace System.Linq
 
                         var index = Array.IndexOf(moveNextTasks, moveNextTask);
 
-                        var enumerator = enumerators[index];
+                        var enumerator = enumerators[index]!; // NB: Only gets set to null after setting task to Never.
 
                         if (!await moveNextTask.ConfigureAwait(false))
                         {

+ 2 - 2
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Min.cs

@@ -10,14 +10,14 @@ namespace System.Linq
 {
     public static partial class AsyncEnumerableEx
     {
-        public static ValueTask<TSource> MinAsync<TSource>(this IAsyncEnumerable<TSource> source, IComparer<TSource> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<TSource> MinAsync<TSource>(this IAsyncEnumerable<TSource> source, IComparer<TSource>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
 
             return Core(source, comparer, cancellationToken);
 
-            static async ValueTask<TSource> Core(IAsyncEnumerable<TSource> source, IComparer<TSource> comparer, CancellationToken cancellationToken)
+            static async ValueTask<TSource> Core(IAsyncEnumerable<TSource> source, IComparer<TSource>? comparer, CancellationToken cancellationToken)
             {
                 comparer ??= Comparer<TSource>.Default;
 

+ 5 - 5
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/MinBy.cs

@@ -20,7 +20,7 @@ namespace System.Linq
             return MinByCore(source, keySelector, comparer: null, cancellationToken);
         }
 
-        public static ValueTask<IList<TSource>> MinByAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<IList<TSource>> MinByAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -52,7 +52,7 @@ namespace System.Linq
         }
 #endif
 
-        public static ValueTask<IList<TSource>> MinByAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<IList<TSource>> MinByAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -74,14 +74,14 @@ namespace System.Linq
         }
 #endif
 
-        private static ValueTask<IList<TSource>> MinByCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer, CancellationToken cancellationToken)
+        private static ValueTask<IList<TSource>> MinByCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey>? comparer, CancellationToken cancellationToken)
         {
             comparer ??= Comparer<TKey>.Default;
 
             return ExtremaBy(source, keySelector, (key, minValue) => -comparer.Compare(key, minValue), cancellationToken);
         }
 
-        private static ValueTask<IList<TSource>> MinByCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IComparer<TKey> comparer, CancellationToken cancellationToken)
+        private static ValueTask<IList<TSource>> MinByCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IComparer<TKey>? comparer, CancellationToken cancellationToken)
         {
             comparer ??= Comparer<TKey>.Default;
 
@@ -89,7 +89,7 @@ namespace System.Linq
         }
 
 #if !NO_DEEP_CANCELLATION
-        private static ValueTask<IList<TSource>> MinByCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IComparer<TKey> comparer, CancellationToken cancellationToken)
+        private static ValueTask<IList<TSource>> MinByCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IComparer<TKey>? comparer, CancellationToken cancellationToken)
         {
             comparer ??= Comparer<TKey>.Default;
 

+ 3 - 5
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Never.cs

@@ -29,7 +29,6 @@ namespace System.Linq
 
                 private CancellationTokenRegistration _registration;
                 private bool _once;
-                private TaskCompletionSource<bool> _task;
 
                 public NeverAsyncEnumerator(CancellationToken token) => _token = token;
 
@@ -38,7 +37,6 @@ namespace System.Linq
                 public ValueTask DisposeAsync()
                 {
                     _registration.Dispose();
-                    _task = null;
                     return default;
                 }
 
@@ -50,9 +48,9 @@ namespace System.Linq
                     }
 
                     _once = true;
-                    _task = new TaskCompletionSource<bool>();
-                    _registration = _token.Register(state => ((NeverAsyncEnumerator)state)._task.SetCanceled(), this);
-                    return new ValueTask<bool>(_task.Task);
+                    var task = new TaskCompletionSource<bool>();
+                    _registration = _token.Register(state => ((TaskCompletionSource<bool>)state).SetCanceled(), task);
+                    return new ValueTask<bool>(task.Task);
                 }
             }
         }

+ 3 - 4
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/OnErrorResumeNext.cs

@@ -4,7 +4,6 @@
 
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Threading;
 using System.Threading.Tasks;
 
 namespace System.Linq
@@ -46,8 +45,8 @@ namespace System.Linq
         {
             private readonly IEnumerable<IAsyncEnumerable<TSource>> _sources;
 
-            private IAsyncEnumerator<TSource> _enumerator;
-            private IEnumerator<IAsyncEnumerable<TSource>> _sourcesEnumerator;
+            private IAsyncEnumerator<TSource>? _enumerator;
+            private IEnumerator<IAsyncEnumerable<TSource>>? _sourcesEnumerator;
 
             public OnErrorResumeNextAsyncIterator(IEnumerable<IAsyncEnumerable<TSource>> sources)
             {
@@ -93,7 +92,7 @@ namespace System.Linq
                         {
                             if (_enumerator == null)
                             {
-                                if (!_sourcesEnumerator.MoveNext())
+                                if (!_sourcesEnumerator!.MoveNext())
                                 {
                                     break; // while -- done, nothing else to do
                                 }

+ 1 - 1
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Return.cs

@@ -43,7 +43,7 @@ namespace System.Linq
 
                 public ValueTask DisposeAsync()
                 {
-                    Current = default;
+                    Current = default!;
                     return default;
                 }
 

+ 1 - 1
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Throw.cs

@@ -51,7 +51,7 @@ namespace System.Linq
                     _moveNextThrows = moveNextThrows;
                 }
 
-                public TValue Current => default;
+                public TValue Current => default!;
 
                 public ValueTask DisposeAsync()
                 {

+ 3 - 3
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Timeout.cs

@@ -28,9 +28,9 @@ namespace System.Linq
             private readonly IAsyncEnumerable<TSource> _source;
             private readonly TimeSpan _timeout;
 
-            private IAsyncEnumerator<TSource> _enumerator;
+            private IAsyncEnumerator<TSource>? _enumerator;
 
-            private Task _loserTask;
+            private Task? _loserTask;
 
             public TimeoutAsyncIterator(IAsyncEnumerable<TSource> source, TimeSpan timeout)
             {
@@ -73,7 +73,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        var moveNext = _enumerator.MoveNextAsync();
+                        var moveNext = _enumerator!.MoveNextAsync();
 
                         if (!moveNext.IsCompleted)
                         {

+ 1 - 0
Ix.NET/Source/System.Linq.Async.Queryable/System.Linq.Async.Queryable.csproj

@@ -2,6 +2,7 @@
 
   <PropertyGroup>
     <TargetFrameworks>net461;netstandard2.0;netstandard2.1;netcoreapp3.0</TargetFrameworks>
+    <NullableContextOptions>enable</NullableContextOptions>
   </PropertyGroup>
 
   <ItemGroup>

+ 1 - 1
Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableExecutor.cs

@@ -15,7 +15,7 @@ namespace System.Linq
     internal class AsyncEnumerableExecutor<T>
     {
         private readonly Expression _expression;
-        private Func<CancellationToken, ValueTask<T>> _func;
+        private Func<CancellationToken, ValueTask<T>>? _func;
 
         /// <summary>
         /// Creates a new execution helper instance for the specified expression tree representing a computation over asynchronous enumerable sequences.

+ 3 - 4
Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableQuery.cs

@@ -4,7 +4,6 @@
 
 using System.Collections.Generic;
 using System.Linq.Expressions;
-using System.Reflection;
 using System.Threading;
 using System.Threading.Tasks;
 
@@ -18,7 +17,7 @@ namespace System.Linq
         /// <summary>
         /// Gets the enumerable sequence obtained from evaluating the expression tree.
         /// </summary>
-        internal abstract object Enumerable { get; }
+        internal abstract object? Enumerable { get; }
 
         /// <summary>
         /// Gets the expression tree representing the asynchronous enumerable sequence.
@@ -33,7 +32,7 @@ namespace System.Linq
     internal class AsyncEnumerableQuery<T> : AsyncEnumerableQuery, IOrderedAsyncQueryable<T>, IAsyncQueryProvider
     {
         private readonly Expression _expression;
-        private IAsyncEnumerable<T> _enumerable;
+        private IAsyncEnumerable<T>? _enumerable;
 
         /// <summary>
         /// Creates a new asynchronous enumerable sequence represented by the specified expression tree.
@@ -72,7 +71,7 @@ namespace System.Linq
         /// <summary>
         /// Gets the enumerable sequence obtained from evaluating the expression tree.
         /// </summary>
-        internal override object Enumerable => _enumerable;
+        internal override object? Enumerable => _enumerable;
 
         /// <summary>
         /// Gets the expression tree representing the asynchronous enumerable sequence.

+ 4 - 4
Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableRewriter.cs

@@ -138,7 +138,7 @@ namespace System.Linq
             return type;
         }
 
-        private static bool ArgsMatch(MethodInfo method, ReadOnlyCollection<Expression> args, Type[] typeArgs)
+        private static bool ArgsMatch(MethodInfo method, ReadOnlyCollection<Expression> args, Type[]? typeArgs)
         {
             //
             // Number of parameters should match the number of arguments to bind.
@@ -388,7 +388,7 @@ namespace System.Linq
             return elemType.MakeArrayType();
         }
 
-        private static MethodInfo FindEnumerableMethod(string name, ReadOnlyCollection<Expression> args, params Type[] typeArgs)
+        private static MethodInfo FindEnumerableMethod(string name, ReadOnlyCollection<Expression> args, params Type[]? typeArgs)
         {
             //
             // Ensure the cached lookup table for AsyncEnumerable methods is initialized.
@@ -418,7 +418,7 @@ namespace System.Linq
             return method;
         }
 
-        private static MethodInfo FindMethod(Type type, string name, ReadOnlyCollection<Expression> args, Type[] typeArgs, BindingFlags flags)
+        private static MethodInfo FindMethod(Type type, string name, ReadOnlyCollection<Expression> args, Type[]? typeArgs, BindingFlags flags)
         {
             //
             // Support the enumerable methods to be defined on another type.
@@ -454,7 +454,7 @@ namespace System.Linq
             return method;
         }
 
-        private static Type FindGenericType(Type definition, Type type)
+        private static Type? FindGenericType(Type definition, Type type)
         {
             while (type != null && type != typeof(object))
             {

+ 49 - 49
Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncQueryable.Generated.cs

@@ -956,7 +956,7 @@ namespace System.Linq
             (s_ContainsAsync__TSource__4__0 ??
             (s_ContainsAsync__TSource__4__0 = new Func<IAsyncQueryable<object>, object, IEqualityComparer<object>, CancellationToken, ValueTask<bool>>(ContainsAsync<object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource);
 
-        public static ValueTask<bool> ContainsAsync<TSource>(this IAsyncQueryable<TSource> source, TSource value, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<bool> ContainsAsync<TSource>(this IAsyncQueryable<TSource> source, TSource value, IEqualityComparer<TSource>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -1074,7 +1074,7 @@ namespace System.Linq
             (s_Distinct__TSource__2__0 ??
             (s_Distinct__TSource__2__0 = new Func<IAsyncQueryable<object>, IEqualityComparer<object>, IAsyncQueryable<object>>(Distinct<object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource);
 
-        public static IAsyncQueryable<TSource> Distinct<TSource>(this IAsyncQueryable<TSource> source, IEqualityComparer<TSource> comparer)
+        public static IAsyncQueryable<TSource> Distinct<TSource>(this IAsyncQueryable<TSource> source, IEqualityComparer<TSource>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -1132,7 +1132,7 @@ namespace System.Linq
             (s_Except__TSource__3__0 ??
             (s_Except__TSource__3__0 = new Func<IAsyncQueryable<object>, IAsyncEnumerable<object>, IEqualityComparer<object>, IAsyncQueryable<object>>(Except<object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource);
 
-        public static IAsyncQueryable<TSource> Except<TSource>(this IAsyncQueryable<TSource> first, IAsyncEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
+        public static IAsyncQueryable<TSource> Except<TSource>(this IAsyncQueryable<TSource> first, IAsyncEnumerable<TSource> second, IEqualityComparer<TSource>? comparer)
         {
             if (first == null)
                 throw new ArgumentNullException(nameof(first));
@@ -1288,7 +1288,7 @@ namespace System.Linq
             (s_GroupBy__TSource_TKey__3__0 ??
             (s_GroupBy__TSource_TKey__3__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, object>>, IEqualityComparer<object>, IAsyncQueryable<IAsyncGrouping<object, object>>>(GroupBy<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static IAsyncQueryable<IAsyncGrouping<TKey, TSource>> GroupBy<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<IAsyncGrouping<TKey, TSource>> GroupBy<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IEqualityComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -1340,7 +1340,7 @@ namespace System.Linq
             (s_GroupBy__TSource_TKey_TResult__4__0 ??
             (s_GroupBy__TSource_TKey_TResult__4__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, object>>, Expression<Func<object, IAsyncEnumerable<object>, object>>, IEqualityComparer<object>, IAsyncQueryable<object>>(GroupBy<object, object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TResult);
 
-        public static IAsyncQueryable<TResult> GroupBy<TSource, TKey, TResult>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, Expression<Func<TKey, IAsyncEnumerable<TSource>, TResult>> resultSelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<TResult> GroupBy<TSource, TKey, TResult>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, Expression<Func<TKey, IAsyncEnumerable<TSource>, TResult>> resultSelector, IEqualityComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -1358,7 +1358,7 @@ namespace System.Linq
             (s_GroupBy__TSource_TKey_TElement__4__0 ??
             (s_GroupBy__TSource_TKey_TElement__4__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, object>>, Expression<Func<object, object>>, IEqualityComparer<object>, IAsyncQueryable<IAsyncGrouping<object, object>>>(GroupBy<object, object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement);
 
-        public static IAsyncQueryable<IAsyncGrouping<TKey, TElement>> GroupBy<TSource, TKey, TElement>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, Expression<Func<TSource, TElement>> elementSelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<IAsyncGrouping<TKey, TElement>> GroupBy<TSource, TKey, TElement>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, Expression<Func<TSource, TElement>> elementSelector, IEqualityComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -1396,7 +1396,7 @@ namespace System.Linq
             (s_GroupBy__TSource_TKey_TElement_TResult__5__0 ??
             (s_GroupBy__TSource_TKey_TElement_TResult__5__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, object>>, Expression<Func<object, object>>, Expression<Func<object, IAsyncEnumerable<object>, object>>, IEqualityComparer<object>, IAsyncQueryable<object>>(GroupBy<object, object, object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement, TResult);
 
-        public static IAsyncQueryable<TResult> GroupBy<TSource, TKey, TElement, TResult>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, Expression<Func<TSource, TElement>> elementSelector, Expression<Func<TKey, IAsyncEnumerable<TElement>, TResult>> resultSelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<TResult> GroupBy<TSource, TKey, TElement, TResult>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, Expression<Func<TSource, TElement>> elementSelector, Expression<Func<TKey, IAsyncEnumerable<TElement>, TResult>> resultSelector, IEqualityComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -1432,7 +1432,7 @@ namespace System.Linq
             (s_GroupByAwait__TSource_TKey__3__0 ??
             (s_GroupByAwait__TSource_TKey__3__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, ValueTask<object>>>, IEqualityComparer<object>, IAsyncQueryable<IAsyncGrouping<object, object>>>(GroupByAwait<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static IAsyncQueryable<IAsyncGrouping<TKey, TSource>> GroupByAwait<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<IAsyncGrouping<TKey, TSource>> GroupByAwait<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, IEqualityComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -1484,7 +1484,7 @@ namespace System.Linq
             (s_GroupByAwait__TSource_TKey_TResult__4__0 ??
             (s_GroupByAwait__TSource_TKey_TResult__4__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, ValueTask<object>>>, Expression<Func<object, IAsyncEnumerable<object>, ValueTask<object>>>, IEqualityComparer<object>, IAsyncQueryable<object>>(GroupByAwait<object, object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TResult);
 
-        public static IAsyncQueryable<TResult> GroupByAwait<TSource, TKey, TResult>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, Expression<Func<TKey, IAsyncEnumerable<TSource>, ValueTask<TResult>>> resultSelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<TResult> GroupByAwait<TSource, TKey, TResult>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, Expression<Func<TKey, IAsyncEnumerable<TSource>, ValueTask<TResult>>> resultSelector, IEqualityComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -1502,7 +1502,7 @@ namespace System.Linq
             (s_GroupByAwait__TSource_TKey_TElement__4__0 ??
             (s_GroupByAwait__TSource_TKey_TElement__4__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, ValueTask<object>>>, Expression<Func<object, ValueTask<object>>>, IEqualityComparer<object>, IAsyncQueryable<IAsyncGrouping<object, object>>>(GroupByAwait<object, object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement);
 
-        public static IAsyncQueryable<IAsyncGrouping<TKey, TElement>> GroupByAwait<TSource, TKey, TElement>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, Expression<Func<TSource, ValueTask<TElement>>> elementSelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<IAsyncGrouping<TKey, TElement>> GroupByAwait<TSource, TKey, TElement>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, Expression<Func<TSource, ValueTask<TElement>>> elementSelector, IEqualityComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -1540,7 +1540,7 @@ namespace System.Linq
             (s_GroupByAwait__TSource_TKey_TElement_TResult__5__0 ??
             (s_GroupByAwait__TSource_TKey_TElement_TResult__5__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, ValueTask<object>>>, Expression<Func<object, ValueTask<object>>>, Expression<Func<object, IAsyncEnumerable<object>, ValueTask<object>>>, IEqualityComparer<object>, IAsyncQueryable<object>>(GroupByAwait<object, object, object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement, TResult);
 
-        public static IAsyncQueryable<TResult> GroupByAwait<TSource, TKey, TElement, TResult>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, Expression<Func<TSource, ValueTask<TElement>>> elementSelector, Expression<Func<TKey, IAsyncEnumerable<TElement>, ValueTask<TResult>>> resultSelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<TResult> GroupByAwait<TSource, TKey, TElement, TResult>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, Expression<Func<TSource, ValueTask<TElement>>> elementSelector, Expression<Func<TKey, IAsyncEnumerable<TElement>, ValueTask<TResult>>> resultSelector, IEqualityComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -1576,7 +1576,7 @@ namespace System.Linq
             (s_GroupByAwaitWithCancellation__TSource_TKey__3__0 ??
             (s_GroupByAwaitWithCancellation__TSource_TKey__3__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, CancellationToken, ValueTask<object>>>, IEqualityComparer<object>, IAsyncQueryable<IAsyncGrouping<object, object>>>(GroupByAwaitWithCancellation<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static IAsyncQueryable<IAsyncGrouping<TKey, TSource>> GroupByAwaitWithCancellation<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<IAsyncGrouping<TKey, TSource>> GroupByAwaitWithCancellation<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, IEqualityComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -1628,7 +1628,7 @@ namespace System.Linq
             (s_GroupByAwaitWithCancellation__TSource_TKey_TResult__4__0 ??
             (s_GroupByAwaitWithCancellation__TSource_TKey_TResult__4__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, CancellationToken, ValueTask<object>>>, Expression<Func<object, IAsyncEnumerable<object>, CancellationToken, ValueTask<object>>>, IEqualityComparer<object>, IAsyncQueryable<object>>(GroupByAwaitWithCancellation<object, object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TResult);
 
-        public static IAsyncQueryable<TResult> GroupByAwaitWithCancellation<TSource, TKey, TResult>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, Expression<Func<TKey, IAsyncEnumerable<TSource>, CancellationToken, ValueTask<TResult>>> resultSelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<TResult> GroupByAwaitWithCancellation<TSource, TKey, TResult>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, Expression<Func<TKey, IAsyncEnumerable<TSource>, CancellationToken, ValueTask<TResult>>> resultSelector, IEqualityComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -1646,7 +1646,7 @@ namespace System.Linq
             (s_GroupByAwaitWithCancellation__TSource_TKey_TElement__4__0 ??
             (s_GroupByAwaitWithCancellation__TSource_TKey_TElement__4__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, CancellationToken, ValueTask<object>>>, Expression<Func<object, CancellationToken, ValueTask<object>>>, IEqualityComparer<object>, IAsyncQueryable<IAsyncGrouping<object, object>>>(GroupByAwaitWithCancellation<object, object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement);
 
-        public static IAsyncQueryable<IAsyncGrouping<TKey, TElement>> GroupByAwaitWithCancellation<TSource, TKey, TElement>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, Expression<Func<TSource, CancellationToken, ValueTask<TElement>>> elementSelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<IAsyncGrouping<TKey, TElement>> GroupByAwaitWithCancellation<TSource, TKey, TElement>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, Expression<Func<TSource, CancellationToken, ValueTask<TElement>>> elementSelector, IEqualityComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -1684,7 +1684,7 @@ namespace System.Linq
             (s_GroupByAwaitWithCancellation__TSource_TKey_TElement_TResult__5__0 ??
             (s_GroupByAwaitWithCancellation__TSource_TKey_TElement_TResult__5__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, CancellationToken, ValueTask<object>>>, Expression<Func<object, CancellationToken, ValueTask<object>>>, Expression<Func<object, IAsyncEnumerable<object>, CancellationToken, ValueTask<object>>>, IEqualityComparer<object>, IAsyncQueryable<object>>(GroupByAwaitWithCancellation<object, object, object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement, TResult);
 
-        public static IAsyncQueryable<TResult> GroupByAwaitWithCancellation<TSource, TKey, TElement, TResult>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, Expression<Func<TSource, CancellationToken, ValueTask<TElement>>> elementSelector, Expression<Func<TKey, IAsyncEnumerable<TElement>, CancellationToken, ValueTask<TResult>>> resultSelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<TResult> GroupByAwaitWithCancellation<TSource, TKey, TElement, TResult>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, Expression<Func<TSource, CancellationToken, ValueTask<TElement>>> elementSelector, Expression<Func<TKey, IAsyncEnumerable<TElement>, CancellationToken, ValueTask<TResult>>> resultSelector, IEqualityComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -1726,7 +1726,7 @@ namespace System.Linq
             (s_GroupJoin__TOuter_TInner_TKey_TResult__6__0 ??
             (s_GroupJoin__TOuter_TInner_TKey_TResult__6__0 = new Func<IAsyncQueryable<object>, IAsyncEnumerable<object>, Expression<Func<object, object>>, Expression<Func<object, object>>, Expression<Func<object, IAsyncEnumerable<object>, object>>, IEqualityComparer<object>, IAsyncQueryable<object>>(GroupJoin<object, object, object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TOuter, TInner, TKey, TResult);
 
-        public static IAsyncQueryable<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this IAsyncQueryable<TOuter> outer, IAsyncEnumerable<TInner> inner, Expression<Func<TOuter, TKey>> outerKeySelector, Expression<Func<TInner, TKey>> innerKeySelector, Expression<Func<TOuter, IAsyncEnumerable<TInner>, TResult>> resultSelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this IAsyncQueryable<TOuter> outer, IAsyncEnumerable<TInner> inner, Expression<Func<TOuter, TKey>> outerKeySelector, Expression<Func<TInner, TKey>> innerKeySelector, Expression<Func<TOuter, IAsyncEnumerable<TInner>, TResult>> resultSelector, IEqualityComparer<TKey>? comparer)
         {
             if (outer == null)
                 throw new ArgumentNullException(nameof(outer));
@@ -1770,7 +1770,7 @@ namespace System.Linq
             (s_GroupJoinAwait__TOuter_TInner_TKey_TResult__6__0 ??
             (s_GroupJoinAwait__TOuter_TInner_TKey_TResult__6__0 = new Func<IAsyncQueryable<object>, IAsyncEnumerable<object>, Expression<Func<object, ValueTask<object>>>, Expression<Func<object, ValueTask<object>>>, Expression<Func<object, IAsyncEnumerable<object>, ValueTask<object>>>, IEqualityComparer<object>, IAsyncQueryable<object>>(GroupJoinAwait<object, object, object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TOuter, TInner, TKey, TResult);
 
-        public static IAsyncQueryable<TResult> GroupJoinAwait<TOuter, TInner, TKey, TResult>(this IAsyncQueryable<TOuter> outer, IAsyncEnumerable<TInner> inner, Expression<Func<TOuter, ValueTask<TKey>>> outerKeySelector, Expression<Func<TInner, ValueTask<TKey>>> innerKeySelector, Expression<Func<TOuter, IAsyncEnumerable<TInner>, ValueTask<TResult>>> resultSelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<TResult> GroupJoinAwait<TOuter, TInner, TKey, TResult>(this IAsyncQueryable<TOuter> outer, IAsyncEnumerable<TInner> inner, Expression<Func<TOuter, ValueTask<TKey>>> outerKeySelector, Expression<Func<TInner, ValueTask<TKey>>> innerKeySelector, Expression<Func<TOuter, IAsyncEnumerable<TInner>, ValueTask<TResult>>> resultSelector, IEqualityComparer<TKey>? comparer)
         {
             if (outer == null)
                 throw new ArgumentNullException(nameof(outer));
@@ -1814,7 +1814,7 @@ namespace System.Linq
             (s_GroupJoinAwaitWithCancellation__TOuter_TInner_TKey_TResult__6__0 ??
             (s_GroupJoinAwaitWithCancellation__TOuter_TInner_TKey_TResult__6__0 = new Func<IAsyncQueryable<object>, IAsyncEnumerable<object>, Expression<Func<object, CancellationToken, ValueTask<object>>>, Expression<Func<object, CancellationToken, ValueTask<object>>>, Expression<Func<object, IAsyncEnumerable<object>, CancellationToken, ValueTask<object>>>, IEqualityComparer<object>, IAsyncQueryable<object>>(GroupJoinAwaitWithCancellation<object, object, object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TOuter, TInner, TKey, TResult);
 
-        public static IAsyncQueryable<TResult> GroupJoinAwaitWithCancellation<TOuter, TInner, TKey, TResult>(this IAsyncQueryable<TOuter> outer, IAsyncEnumerable<TInner> inner, Expression<Func<TOuter, CancellationToken, ValueTask<TKey>>> outerKeySelector, Expression<Func<TInner, CancellationToken, ValueTask<TKey>>> innerKeySelector, Expression<Func<TOuter, IAsyncEnumerable<TInner>, CancellationToken, ValueTask<TResult>>> resultSelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<TResult> GroupJoinAwaitWithCancellation<TOuter, TInner, TKey, TResult>(this IAsyncQueryable<TOuter> outer, IAsyncEnumerable<TInner> inner, Expression<Func<TOuter, CancellationToken, ValueTask<TKey>>> outerKeySelector, Expression<Func<TInner, CancellationToken, ValueTask<TKey>>> innerKeySelector, Expression<Func<TOuter, IAsyncEnumerable<TInner>, CancellationToken, ValueTask<TResult>>> resultSelector, IEqualityComparer<TKey>? comparer)
         {
             if (outer == null)
                 throw new ArgumentNullException(nameof(outer));
@@ -1852,7 +1852,7 @@ namespace System.Linq
             (s_Intersect__TSource__3__0 ??
             (s_Intersect__TSource__3__0 = new Func<IAsyncQueryable<object>, IAsyncEnumerable<object>, IEqualityComparer<object>, IAsyncQueryable<object>>(Intersect<object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource);
 
-        public static IAsyncQueryable<TSource> Intersect<TSource>(this IAsyncQueryable<TSource> first, IAsyncEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
+        public static IAsyncQueryable<TSource> Intersect<TSource>(this IAsyncQueryable<TSource> first, IAsyncEnumerable<TSource> second, IEqualityComparer<TSource>? comparer)
         {
             if (first == null)
                 throw new ArgumentNullException(nameof(first));
@@ -1890,7 +1890,7 @@ namespace System.Linq
             (s_Join__TOuter_TInner_TKey_TResult__6__0 ??
             (s_Join__TOuter_TInner_TKey_TResult__6__0 = new Func<IAsyncQueryable<object>, IAsyncEnumerable<object>, Expression<Func<object, object>>, Expression<Func<object, object>>, Expression<Func<object, object, object>>, IEqualityComparer<object>, IAsyncQueryable<object>>(Join<object, object, object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TOuter, TInner, TKey, TResult);
 
-        public static IAsyncQueryable<TResult> Join<TOuter, TInner, TKey, TResult>(this IAsyncQueryable<TOuter> outer, IAsyncEnumerable<TInner> inner, Expression<Func<TOuter, TKey>> outerKeySelector, Expression<Func<TInner, TKey>> innerKeySelector, Expression<Func<TOuter, TInner, TResult>> resultSelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<TResult> Join<TOuter, TInner, TKey, TResult>(this IAsyncQueryable<TOuter> outer, IAsyncEnumerable<TInner> inner, Expression<Func<TOuter, TKey>> outerKeySelector, Expression<Func<TInner, TKey>> innerKeySelector, Expression<Func<TOuter, TInner, TResult>> resultSelector, IEqualityComparer<TKey>? comparer)
         {
             if (outer == null)
                 throw new ArgumentNullException(nameof(outer));
@@ -1934,7 +1934,7 @@ namespace System.Linq
             (s_JoinAwait__TOuter_TInner_TKey_TResult__6__0 ??
             (s_JoinAwait__TOuter_TInner_TKey_TResult__6__0 = new Func<IAsyncQueryable<object>, IAsyncEnumerable<object>, Expression<Func<object, ValueTask<object>>>, Expression<Func<object, ValueTask<object>>>, Expression<Func<object, object, ValueTask<object>>>, IEqualityComparer<object>, IAsyncQueryable<object>>(JoinAwait<object, object, object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TOuter, TInner, TKey, TResult);
 
-        public static IAsyncQueryable<TResult> JoinAwait<TOuter, TInner, TKey, TResult>(this IAsyncQueryable<TOuter> outer, IAsyncEnumerable<TInner> inner, Expression<Func<TOuter, ValueTask<TKey>>> outerKeySelector, Expression<Func<TInner, ValueTask<TKey>>> innerKeySelector, Expression<Func<TOuter, TInner, ValueTask<TResult>>> resultSelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<TResult> JoinAwait<TOuter, TInner, TKey, TResult>(this IAsyncQueryable<TOuter> outer, IAsyncEnumerable<TInner> inner, Expression<Func<TOuter, ValueTask<TKey>>> outerKeySelector, Expression<Func<TInner, ValueTask<TKey>>> innerKeySelector, Expression<Func<TOuter, TInner, ValueTask<TResult>>> resultSelector, IEqualityComparer<TKey>? comparer)
         {
             if (outer == null)
                 throw new ArgumentNullException(nameof(outer));
@@ -1978,7 +1978,7 @@ namespace System.Linq
             (s_JoinAwaitWithCancellation__TOuter_TInner_TKey_TResult__6__0 ??
             (s_JoinAwaitWithCancellation__TOuter_TInner_TKey_TResult__6__0 = new Func<IAsyncQueryable<object>, IAsyncEnumerable<object>, Expression<Func<object, CancellationToken, ValueTask<object>>>, Expression<Func<object, CancellationToken, ValueTask<object>>>, Expression<Func<object, object, CancellationToken, ValueTask<object>>>, IEqualityComparer<object>, IAsyncQueryable<object>>(JoinAwaitWithCancellation<object, object, object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TOuter, TInner, TKey, TResult);
 
-        public static IAsyncQueryable<TResult> JoinAwaitWithCancellation<TOuter, TInner, TKey, TResult>(this IAsyncQueryable<TOuter> outer, IAsyncEnumerable<TInner> inner, Expression<Func<TOuter, CancellationToken, ValueTask<TKey>>> outerKeySelector, Expression<Func<TInner, CancellationToken, ValueTask<TKey>>> innerKeySelector, Expression<Func<TOuter, TInner, CancellationToken, ValueTask<TResult>>> resultSelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncQueryable<TResult> JoinAwaitWithCancellation<TOuter, TInner, TKey, TResult>(this IAsyncQueryable<TOuter> outer, IAsyncEnumerable<TInner> inner, Expression<Func<TOuter, CancellationToken, ValueTask<TKey>>> outerKeySelector, Expression<Func<TInner, CancellationToken, ValueTask<TKey>>> innerKeySelector, Expression<Func<TOuter, TInner, CancellationToken, ValueTask<TResult>>> resultSelector, IEqualityComparer<TKey>? comparer)
         {
             if (outer == null)
                 throw new ArgumentNullException(nameof(outer));
@@ -3580,7 +3580,7 @@ namespace System.Linq
             (s_OrderBy__TSource_TKey__3__0 ??
             (s_OrderBy__TSource_TKey__3__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, object>>, IComparer<object>, IOrderedAsyncQueryable<object>>(OrderBy<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static IOrderedAsyncQueryable<TSource> OrderBy<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IComparer<TKey> comparer)
+        public static IOrderedAsyncQueryable<TSource> OrderBy<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -3612,7 +3612,7 @@ namespace System.Linq
             (s_OrderByAwait__TSource_TKey__3__0 ??
             (s_OrderByAwait__TSource_TKey__3__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, ValueTask<object>>>, IComparer<object>, IOrderedAsyncQueryable<object>>(OrderByAwait<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static IOrderedAsyncQueryable<TSource> OrderByAwait<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, IComparer<TKey> comparer)
+        public static IOrderedAsyncQueryable<TSource> OrderByAwait<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, IComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -3644,7 +3644,7 @@ namespace System.Linq
             (s_OrderByAwaitWithCancellation__TSource_TKey__3__0 ??
             (s_OrderByAwaitWithCancellation__TSource_TKey__3__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, CancellationToken, ValueTask<object>>>, IComparer<object>, IOrderedAsyncQueryable<object>>(OrderByAwaitWithCancellation<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static IOrderedAsyncQueryable<TSource> OrderByAwaitWithCancellation<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, IComparer<TKey> comparer)
+        public static IOrderedAsyncQueryable<TSource> OrderByAwaitWithCancellation<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, IComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -3676,7 +3676,7 @@ namespace System.Linq
             (s_OrderByDescending__TSource_TKey__3__0 ??
             (s_OrderByDescending__TSource_TKey__3__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, object>>, IComparer<object>, IOrderedAsyncQueryable<object>>(OrderByDescending<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static IOrderedAsyncQueryable<TSource> OrderByDescending<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IComparer<TKey> comparer)
+        public static IOrderedAsyncQueryable<TSource> OrderByDescending<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -3708,7 +3708,7 @@ namespace System.Linq
             (s_OrderByDescendingAwait__TSource_TKey__3__0 ??
             (s_OrderByDescendingAwait__TSource_TKey__3__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, ValueTask<object>>>, IComparer<object>, IOrderedAsyncQueryable<object>>(OrderByDescendingAwait<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static IOrderedAsyncQueryable<TSource> OrderByDescendingAwait<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, IComparer<TKey> comparer)
+        public static IOrderedAsyncQueryable<TSource> OrderByDescendingAwait<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, IComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -3740,7 +3740,7 @@ namespace System.Linq
             (s_OrderByDescendingAwaitWithCancellation__TSource_TKey__3__0 ??
             (s_OrderByDescendingAwaitWithCancellation__TSource_TKey__3__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, CancellationToken, ValueTask<object>>>, IComparer<object>, IOrderedAsyncQueryable<object>>(OrderByDescendingAwaitWithCancellation<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static IOrderedAsyncQueryable<TSource> OrderByDescendingAwaitWithCancellation<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, IComparer<TKey> comparer)
+        public static IOrderedAsyncQueryable<TSource> OrderByDescendingAwaitWithCancellation<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, IComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -4100,7 +4100,7 @@ namespace System.Linq
             (s_SequenceEqualAsync__TSource__4__0 ??
             (s_SequenceEqualAsync__TSource__4__0 = new Func<IAsyncQueryable<object>, IAsyncEnumerable<object>, IEqualityComparer<object>, CancellationToken, ValueTask<bool>>(SequenceEqualAsync<object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource);
 
-        public static ValueTask<bool> SequenceEqualAsync<TSource>(this IAsyncQueryable<TSource> first, IAsyncEnumerable<TSource> second, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<bool> SequenceEqualAsync<TSource>(this IAsyncQueryable<TSource> first, IAsyncEnumerable<TSource> second, IEqualityComparer<TSource>? comparer, CancellationToken cancellationToken = default)
         {
             if (first == null)
                 throw new ArgumentNullException(nameof(first));
@@ -5124,7 +5124,7 @@ namespace System.Linq
             (s_ThenBy__TSource_TKey__3__0 ??
             (s_ThenBy__TSource_TKey__3__0 = new Func<IOrderedAsyncQueryable<object>, Expression<Func<object, object>>, IComparer<object>, IOrderedAsyncQueryable<object>>(ThenBy<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static IOrderedAsyncQueryable<TSource> ThenBy<TSource, TKey>(this IOrderedAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IComparer<TKey> comparer)
+        public static IOrderedAsyncQueryable<TSource> ThenBy<TSource, TKey>(this IOrderedAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -5156,7 +5156,7 @@ namespace System.Linq
             (s_ThenByAwait__TSource_TKey__3__0 ??
             (s_ThenByAwait__TSource_TKey__3__0 = new Func<IOrderedAsyncQueryable<object>, Expression<Func<object, ValueTask<object>>>, IComparer<object>, IOrderedAsyncQueryable<object>>(ThenByAwait<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static IOrderedAsyncQueryable<TSource> ThenByAwait<TSource, TKey>(this IOrderedAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, IComparer<TKey> comparer)
+        public static IOrderedAsyncQueryable<TSource> ThenByAwait<TSource, TKey>(this IOrderedAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, IComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -5188,7 +5188,7 @@ namespace System.Linq
             (s_ThenByAwaitWithCancellation__TSource_TKey__3__0 ??
             (s_ThenByAwaitWithCancellation__TSource_TKey__3__0 = new Func<IOrderedAsyncQueryable<object>, Expression<Func<object, CancellationToken, ValueTask<object>>>, IComparer<object>, IOrderedAsyncQueryable<object>>(ThenByAwaitWithCancellation<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static IOrderedAsyncQueryable<TSource> ThenByAwaitWithCancellation<TSource, TKey>(this IOrderedAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, IComparer<TKey> comparer)
+        public static IOrderedAsyncQueryable<TSource> ThenByAwaitWithCancellation<TSource, TKey>(this IOrderedAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, IComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -5220,7 +5220,7 @@ namespace System.Linq
             (s_ThenByDescending__TSource_TKey__3__0 ??
             (s_ThenByDescending__TSource_TKey__3__0 = new Func<IOrderedAsyncQueryable<object>, Expression<Func<object, object>>, IComparer<object>, IOrderedAsyncQueryable<object>>(ThenByDescending<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static IOrderedAsyncQueryable<TSource> ThenByDescending<TSource, TKey>(this IOrderedAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IComparer<TKey> comparer)
+        public static IOrderedAsyncQueryable<TSource> ThenByDescending<TSource, TKey>(this IOrderedAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -5252,7 +5252,7 @@ namespace System.Linq
             (s_ThenByDescendingAwait__TSource_TKey__3__0 ??
             (s_ThenByDescendingAwait__TSource_TKey__3__0 = new Func<IOrderedAsyncQueryable<object>, Expression<Func<object, ValueTask<object>>>, IComparer<object>, IOrderedAsyncQueryable<object>>(ThenByDescendingAwait<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static IOrderedAsyncQueryable<TSource> ThenByDescendingAwait<TSource, TKey>(this IOrderedAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, IComparer<TKey> comparer)
+        public static IOrderedAsyncQueryable<TSource> ThenByDescendingAwait<TSource, TKey>(this IOrderedAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, IComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -5284,7 +5284,7 @@ namespace System.Linq
             (s_ThenByDescendingAwaitWithCancellation__TSource_TKey__3__0 ??
             (s_ThenByDescendingAwaitWithCancellation__TSource_TKey__3__0 = new Func<IOrderedAsyncQueryable<object>, Expression<Func<object, CancellationToken, ValueTask<object>>>, IComparer<object>, IOrderedAsyncQueryable<object>>(ThenByDescendingAwaitWithCancellation<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static IOrderedAsyncQueryable<TSource> ThenByDescendingAwaitWithCancellation<TSource, TKey>(this IOrderedAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, IComparer<TKey> comparer)
+        public static IOrderedAsyncQueryable<TSource> ThenByDescendingAwaitWithCancellation<TSource, TKey>(this IOrderedAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, IComparer<TKey>? comparer)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -5330,7 +5330,7 @@ namespace System.Linq
             (s_ToDictionaryAsync__TSource_TKey__4__0 ??
             (s_ToDictionaryAsync__TSource_TKey__4__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, object>>, IEqualityComparer<object>, CancellationToken, ValueTask<Dictionary<object, object>>>(ToDictionaryAsync<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static ValueTask<Dictionary<TKey, TSource>> ToDictionaryAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<Dictionary<TKey, TSource>> ToDictionaryAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -5364,7 +5364,7 @@ namespace System.Linq
             (s_ToDictionaryAsync__TSource_TKey_TElement__5__0 ??
             (s_ToDictionaryAsync__TSource_TKey_TElement__5__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, object>>, Expression<Func<object, object>>, IEqualityComparer<object>, CancellationToken, ValueTask<Dictionary<object, object>>>(ToDictionaryAsync<object, object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement);
 
-        public static ValueTask<Dictionary<TKey, TElement>> ToDictionaryAsync<TSource, TKey, TElement>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, Expression<Func<TSource, TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<Dictionary<TKey, TElement>> ToDictionaryAsync<TSource, TKey, TElement>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, Expression<Func<TSource, TElement>> elementSelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -5398,7 +5398,7 @@ namespace System.Linq
             (s_ToDictionaryAwaitAsync__TSource_TKey__4__0 ??
             (s_ToDictionaryAwaitAsync__TSource_TKey__4__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, ValueTask<object>>>, IEqualityComparer<object>, CancellationToken, ValueTask<Dictionary<object, object>>>(ToDictionaryAwaitAsync<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static ValueTask<Dictionary<TKey, TSource>> ToDictionaryAwaitAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<Dictionary<TKey, TSource>> ToDictionaryAwaitAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -5432,7 +5432,7 @@ namespace System.Linq
             (s_ToDictionaryAwaitAsync__TSource_TKey_TElement__5__0 ??
             (s_ToDictionaryAwaitAsync__TSource_TKey_TElement__5__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, ValueTask<object>>>, Expression<Func<object, ValueTask<object>>>, IEqualityComparer<object>, CancellationToken, ValueTask<Dictionary<object, object>>>(ToDictionaryAwaitAsync<object, object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement);
 
-        public static ValueTask<Dictionary<TKey, TElement>> ToDictionaryAwaitAsync<TSource, TKey, TElement>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, Expression<Func<TSource, ValueTask<TElement>>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<Dictionary<TKey, TElement>> ToDictionaryAwaitAsync<TSource, TKey, TElement>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, Expression<Func<TSource, ValueTask<TElement>>> elementSelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -5466,7 +5466,7 @@ namespace System.Linq
             (s_ToDictionaryAwaitWithCancellationAsync__TSource_TKey__4__0 ??
             (s_ToDictionaryAwaitWithCancellationAsync__TSource_TKey__4__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, CancellationToken, ValueTask<object>>>, IEqualityComparer<object>, CancellationToken, ValueTask<Dictionary<object, object>>>(ToDictionaryAwaitWithCancellationAsync<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static ValueTask<Dictionary<TKey, TSource>> ToDictionaryAwaitWithCancellationAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<Dictionary<TKey, TSource>> ToDictionaryAwaitWithCancellationAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -5500,7 +5500,7 @@ namespace System.Linq
             (s_ToDictionaryAwaitWithCancellationAsync__TSource_TKey_TElement__5__0 ??
             (s_ToDictionaryAwaitWithCancellationAsync__TSource_TKey_TElement__5__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, CancellationToken, ValueTask<object>>>, Expression<Func<object, CancellationToken, ValueTask<object>>>, IEqualityComparer<object>, CancellationToken, ValueTask<Dictionary<object, object>>>(ToDictionaryAwaitWithCancellationAsync<object, object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement);
 
-        public static ValueTask<Dictionary<TKey, TElement>> ToDictionaryAwaitWithCancellationAsync<TSource, TKey, TElement>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, Expression<Func<TSource, CancellationToken, ValueTask<TElement>>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<Dictionary<TKey, TElement>> ToDictionaryAwaitWithCancellationAsync<TSource, TKey, TElement>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, Expression<Func<TSource, CancellationToken, ValueTask<TElement>>> elementSelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -5532,7 +5532,7 @@ namespace System.Linq
             (s_ToHashSetAsync__TSource__3__0 ??
             (s_ToHashSetAsync__TSource__3__0 = new Func<IAsyncQueryable<object>, IEqualityComparer<object>, CancellationToken, ValueTask<HashSet<object>>>(ToHashSetAsync<object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource);
 
-        public static ValueTask<HashSet<TSource>> ToHashSetAsync<TSource>(this IAsyncQueryable<TSource> source, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<HashSet<TSource>> ToHashSetAsync<TSource>(this IAsyncQueryable<TSource> source, IEqualityComparer<TSource>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -5576,7 +5576,7 @@ namespace System.Linq
             (s_ToLookupAsync__TSource_TKey__4__0 ??
             (s_ToLookupAsync__TSource_TKey__4__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, object>>, IEqualityComparer<object>, CancellationToken, ValueTask<ILookup<object, object>>>(ToLookupAsync<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static ValueTask<ILookup<TKey, TSource>> ToLookupAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<ILookup<TKey, TSource>> ToLookupAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -5610,7 +5610,7 @@ namespace System.Linq
             (s_ToLookupAsync__TSource_TKey_TElement__5__0 ??
             (s_ToLookupAsync__TSource_TKey_TElement__5__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, object>>, Expression<Func<object, object>>, IEqualityComparer<object>, CancellationToken, ValueTask<ILookup<object, object>>>(ToLookupAsync<object, object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement);
 
-        public static ValueTask<ILookup<TKey, TElement>> ToLookupAsync<TSource, TKey, TElement>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, Expression<Func<TSource, TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<ILookup<TKey, TElement>> ToLookupAsync<TSource, TKey, TElement>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, Expression<Func<TSource, TElement>> elementSelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -5644,7 +5644,7 @@ namespace System.Linq
             (s_ToLookupAwaitAsync__TSource_TKey__4__0 ??
             (s_ToLookupAwaitAsync__TSource_TKey__4__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, ValueTask<object>>>, IEqualityComparer<object>, CancellationToken, ValueTask<ILookup<object, object>>>(ToLookupAwaitAsync<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static ValueTask<ILookup<TKey, TSource>> ToLookupAwaitAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<ILookup<TKey, TSource>> ToLookupAwaitAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -5678,7 +5678,7 @@ namespace System.Linq
             (s_ToLookupAwaitAsync__TSource_TKey_TElement__5__0 ??
             (s_ToLookupAwaitAsync__TSource_TKey_TElement__5__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, ValueTask<object>>>, Expression<Func<object, ValueTask<object>>>, IEqualityComparer<object>, CancellationToken, ValueTask<ILookup<object, object>>>(ToLookupAwaitAsync<object, object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement);
 
-        public static ValueTask<ILookup<TKey, TElement>> ToLookupAwaitAsync<TSource, TKey, TElement>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, Expression<Func<TSource, ValueTask<TElement>>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<ILookup<TKey, TElement>> ToLookupAwaitAsync<TSource, TKey, TElement>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, ValueTask<TKey>>> keySelector, Expression<Func<TSource, ValueTask<TElement>>> elementSelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -5712,7 +5712,7 @@ namespace System.Linq
             (s_ToLookupAwaitWithCancellationAsync__TSource_TKey__4__0 ??
             (s_ToLookupAwaitWithCancellationAsync__TSource_TKey__4__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, CancellationToken, ValueTask<object>>>, IEqualityComparer<object>, CancellationToken, ValueTask<ILookup<object, object>>>(ToLookupAwaitWithCancellationAsync<object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey);
 
-        public static ValueTask<ILookup<TKey, TSource>> ToLookupAwaitWithCancellationAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<ILookup<TKey, TSource>> ToLookupAwaitWithCancellationAsync<TSource, TKey>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -5746,7 +5746,7 @@ namespace System.Linq
             (s_ToLookupAwaitWithCancellationAsync__TSource_TKey_TElement__5__0 ??
             (s_ToLookupAwaitWithCancellationAsync__TSource_TKey_TElement__5__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, CancellationToken, ValueTask<object>>>, Expression<Func<object, CancellationToken, ValueTask<object>>>, IEqualityComparer<object>, CancellationToken, ValueTask<ILookup<object, object>>>(ToLookupAwaitWithCancellationAsync<object, object, object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement);
 
-        public static ValueTask<ILookup<TKey, TElement>> ToLookupAwaitWithCancellationAsync<TSource, TKey, TElement>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, Expression<Func<TSource, CancellationToken, ValueTask<TElement>>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<ILookup<TKey, TElement>> ToLookupAwaitWithCancellationAsync<TSource, TKey, TElement>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<TKey>>> keySelector, Expression<Func<TSource, CancellationToken, ValueTask<TElement>>> elementSelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
@@ -5780,7 +5780,7 @@ namespace System.Linq
             (s_Union__TSource__3__0 ??
             (s_Union__TSource__3__0 = new Func<IAsyncQueryable<object>, IAsyncEnumerable<object>, IEqualityComparer<object>, IAsyncQueryable<object>>(Union<object>).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource);
 
-        public static IAsyncQueryable<TSource> Union<TSource>(this IAsyncQueryable<TSource> first, IAsyncEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
+        public static IAsyncQueryable<TSource> Union<TSource>(this IAsyncQueryable<TSource> first, IAsyncEnumerable<TSource> second, IEqualityComparer<TSource>? comparer)
         {
             if (first == null)
                 throw new ArgumentNullException(nameof(first));

+ 3 - 2
Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncQueryable.Generated.tt

@@ -3,8 +3,9 @@
 // See the LICENSE file in the project root for more information. 
 
 <#@ template debug="false" hostspecific="false" language="C#" #>
-<#@ assembly name="$(ProjectDir)\..\System.Linq.Async\bin\$(Configuration)\net46\System.Threading.Tasks.Extensions.dll" #>
-<#@ assembly name="$(ProjectDir)\..\System.Linq.Async\bin\$(Configuration)\net46\System.Linq.Async.dll" #>
+<#@ assembly name="$(ProjectDir)\..\System.Linq.Async\bin\$(Configuration)\net461\Microsoft.Bcl.AsyncInterfaces.dll" #>
+<#@ assembly name="$(ProjectDir)\..\System.Linq.Async\bin\$(Configuration)\net461\System.Threading.Tasks.Extensions.dll" #>
+<#@ assembly name="$(ProjectDir)\..\System.Linq.Async\bin\$(Configuration)\net461\System.Linq.Async.dll" #>
 <#@ output extension=".cs" #>
 <#
 var asyncEnumerableType = typeof(AsyncEnumerable);

+ 1 - 0
Ix.NET/Source/System.Linq.Async/System.Linq.Async.csproj

@@ -2,6 +2,7 @@
 
   <PropertyGroup>
     <TargetFrameworks>net461;netstandard2.0;netstandard2.1;netcoreapp3.0</TargetFrameworks>
+    <NullableContextOptions>enable</NullableContextOptions>
   </PropertyGroup>
 
   <ItemGroup>

+ 1 - 1
Ix.NET/Source/System.Linq.Async/System/Linq/AsyncEnumerableHelpers.cs

@@ -102,7 +102,7 @@ namespace System.Collections.Generic
             return result;
         }
 
-        internal static async Task<Set<T>> ToSet<T>(IAsyncEnumerable<T> source, IEqualityComparer<T> comparer, CancellationToken cancellationToken)
+        internal static async Task<Set<T>> ToSet<T>(IAsyncEnumerable<T> source, IEqualityComparer<T>? comparer, CancellationToken cancellationToken)
         {
             var set = new Set<T>(comparer);
 

+ 3 - 3
Ix.NET/Source/System.Linq.Async/System/Linq/AsyncEnumerablePartition.cs

@@ -21,7 +21,7 @@ namespace System.Linq
         private readonly int _minIndexInclusive;
         private readonly int _maxIndexInclusive; // -1 if we want everything past _minIndexInclusive.
                                                  // If this is -1, it's impossible to set a limit on the count.
-        private IAsyncEnumerator<TSource> _enumerator;
+        private IAsyncEnumerator<TSource>? _enumerator;
 
         internal AsyncEnumerablePartition(IAsyncEnumerable<TSource> source, int minIndexInclusive, int maxIndexInclusive)
         {
@@ -122,7 +122,7 @@ namespace System.Linq
                 case AsyncIteratorState.Iterating:
                     if (!_hasSkipped)
                     {
-                        if (!await SkipBeforeFirstAsync(_enumerator).ConfigureAwait(false))
+                        if (!await SkipBeforeFirstAsync(_enumerator!).ConfigureAwait(false))
                         {
                             // Reached the end before we finished skipping.
                             break;
@@ -131,7 +131,7 @@ namespace System.Linq
                         _hasSkipped = true;
                     }
 
-                    if ((!HasLimit || _taken < Limit) && await _enumerator.MoveNextAsync().ConfigureAwait(false))
+                    if ((!HasLimit || _taken < Limit) && await _enumerator!.MoveNextAsync().ConfigureAwait(false))
                     {
                         if (HasLimit)
                         {

+ 1 - 1
Ix.NET/Source/System.Linq.Async/System/Linq/AsyncEnumerator.cs

@@ -63,7 +63,7 @@ namespace System.Collections.Generic
         {
             private readonly Func<T> _currentFunc;
             private readonly Func<ValueTask<bool>> _moveNext;
-            private Func<ValueTask> _dispose;
+            private Func<ValueTask>? _dispose;
 
             public AnonymousAsyncIterator(Func<ValueTask<bool>> moveNext, Func<T> currentFunc, Func<ValueTask> dispose)
             {

+ 2 - 2
Ix.NET/Source/System.Linq.Async/System/Linq/AsyncIterator.cs

@@ -83,13 +83,13 @@ namespace System.Linq
 
     internal abstract class AsyncIterator<TSource> : AsyncIteratorBase<TSource>
     {
-        protected TSource _current;
+        protected TSource _current = default!;
 
         public override TSource Current => _current;
 
         public override ValueTask DisposeAsync()
         {
-            _current = default;
+            _current = default!;
 
             return base.DisposeAsync();
         }

+ 3 - 3
Ix.NET/Source/System.Linq.Async/System/Linq/Disposables.cs

@@ -30,8 +30,8 @@ namespace System.Linq
 
     internal sealed class BinaryDisposable : IDisposable
     {
-        private IDisposable _d1;
-        private IDisposable _d2;
+        private IDisposable? _d1;
+        private IDisposable? _d2;
 
         public BinaryDisposable(IDisposable d1, IDisposable d2)
         {
@@ -57,7 +57,7 @@ namespace System.Linq
 
     internal sealed class AnonymousDisposable : IDisposable
     {
-        private Action _action;
+        private Action? _action;
 
         public AnonymousDisposable(Action action)
         {

+ 3 - 3
Ix.NET/Source/System.Linq.Async/System/Linq/IOrderedAsyncEnumerable.cs

@@ -10,11 +10,11 @@ namespace System.Linq
 {
     public interface IOrderedAsyncEnumerable<out TElement> : IAsyncEnumerable<TElement>
     {
-        IOrderedAsyncEnumerable<TElement> CreateOrderedEnumerable<TKey>(Func<TElement, TKey> keySelector, IComparer<TKey> comparer, bool descending);
-        IOrderedAsyncEnumerable<TElement> CreateOrderedEnumerable<TKey>(Func<TElement, ValueTask<TKey>> keySelector, IComparer<TKey> comparer, bool descending);
+        IOrderedAsyncEnumerable<TElement> CreateOrderedEnumerable<TKey>(Func<TElement, TKey> keySelector, IComparer<TKey>? comparer, bool descending);
+        IOrderedAsyncEnumerable<TElement> CreateOrderedEnumerable<TKey>(Func<TElement, ValueTask<TKey>> keySelector, IComparer<TKey>? comparer, bool descending);
 
 #if !NO_DEEP_CANCELLATION
-        IOrderedAsyncEnumerable<TElement> CreateOrderedEnumerable<TKey>(Func<TElement, CancellationToken, ValueTask<TKey>> keySelector, IComparer<TKey> comparer, bool descending);
+        IOrderedAsyncEnumerable<TElement> CreateOrderedEnumerable<TKey>(Func<TElement, CancellationToken, ValueTask<TKey>> keySelector, IComparer<TKey>? comparer, bool descending);
 #endif
     }
 }

+ 8 - 8
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/AppendPrepend.cs

@@ -41,7 +41,7 @@ namespace System.Linq
         private abstract class AppendPrependAsyncIterator<TSource> : AsyncIterator<TSource>, IAsyncIListProvider<TSource>
         {
             protected readonly IAsyncEnumerable<TSource> _source;
-            protected IAsyncEnumerator<TSource> _enumerator;
+            protected IAsyncEnumerator<TSource>? _enumerator;
 
             protected AppendPrependAsyncIterator(IAsyncEnumerable<TSource> source)
             {
@@ -61,7 +61,7 @@ namespace System.Linq
 
             protected async Task<bool> LoadFromEnumeratorAsync()
             {
-                if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
+                if (await _enumerator!.MoveNextAsync().ConfigureAwait(false))
                 {
                     _current = _enumerator.Current;
                     return true;
@@ -261,15 +261,15 @@ namespace System.Linq
 
         private sealed class AppendPrependNAsyncIterator<TSource> : AppendPrependAsyncIterator<TSource>
         {
-            private readonly SingleLinkedNode<TSource> _prepended;
-            private readonly SingleLinkedNode<TSource> _appended;
+            private readonly SingleLinkedNode<TSource>? _prepended;
+            private readonly SingleLinkedNode<TSource>? _appended;
             private readonly int _prependCount;
             private readonly int _appendCount;
-            private SingleLinkedNode<TSource> _node;
+            private SingleLinkedNode<TSource>? _node;
             private int _mode;
-            private IEnumerator<TSource> _appendedEnumerator;
+            private IEnumerator<TSource>? _appendedEnumerator;
 
-            public AppendPrependNAsyncIterator(IAsyncEnumerable<TSource> source, SingleLinkedNode<TSource> prepended, SingleLinkedNode<TSource> appended, int prependCount, int appendCount)
+            public AppendPrependNAsyncIterator(IAsyncEnumerable<TSource> source, SingleLinkedNode<TSource>? prepended, SingleLinkedNode<TSource>? appended, int prependCount, int appendCount)
                 : base(source)
             {
                 Debug.Assert(prepended != null || appended != null);
@@ -346,7 +346,7 @@ namespace System.Linq
 
 
                             case 4:
-                                if (_appendedEnumerator.MoveNext())
+                                if (_appendedEnumerator!.MoveNext())
                                 {
                                     _current = _appendedEnumerator.Current;
                                     return true;

+ 6 - 6
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Concat.cs

@@ -47,7 +47,7 @@ namespace System.Linq
                 return new ConcatNAsyncIterator<TSource>(this, next, 2);
             }
 
-            internal override IAsyncEnumerable<TSource> GetAsyncEnumerable(int index)
+            internal override IAsyncEnumerable<TSource>? GetAsyncEnumerable(int index)
             {
                 switch (index)
                 {
@@ -64,7 +64,7 @@ namespace System.Linq
         private abstract class ConcatAsyncIterator<TSource> : AsyncIterator<TSource>, IAsyncIListProvider<TSource>
         {
             private int _counter;
-            private IAsyncEnumerator<TSource> _enumerator;
+            private IAsyncEnumerator<TSource>? _enumerator;
 
             public ValueTask<TSource[]> ToArrayAsync(CancellationToken cancellationToken)
             {
@@ -140,7 +140,7 @@ namespace System.Linq
             {
                 if (_state == AsyncIteratorState.Allocated)
                 {
-                    _enumerator = GetAsyncEnumerable(0).GetAsyncEnumerator(_cancellationToken);
+                    _enumerator = GetAsyncEnumerable(0)!.GetAsyncEnumerator(_cancellationToken);
                     _state = AsyncIteratorState.Iterating;
                     _counter = 2;
                 }
@@ -149,7 +149,7 @@ namespace System.Linq
                 {
                     while (true)
                     {
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
+                        if (await _enumerator!.MoveNextAsync().ConfigureAwait(false))
                         {
                             _current = _enumerator.Current;
                             return true;
@@ -178,7 +178,7 @@ namespace System.Linq
 
             internal abstract ConcatAsyncIterator<TSource> Concat(IAsyncEnumerable<TSource> next);
 
-            internal abstract IAsyncEnumerable<TSource> GetAsyncEnumerable(int index);
+            internal abstract IAsyncEnumerable<TSource>? GetAsyncEnumerable(int index);
         }
 
         // To handle chains of >= 3 sources, we chain the concat iterators together and allow
@@ -222,7 +222,7 @@ namespace System.Linq
                 return new ConcatNAsyncIterator<TSource>(this, next, _nextIndex + 1);
             }
 
-            internal override IAsyncEnumerable<TSource> GetAsyncEnumerable(int index)
+            internal override IAsyncEnumerable<TSource>? GetAsyncEnumerable(int index)
             {
                 if (index > _nextIndex)
                 {

+ 1 - 1
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Contains.cs

@@ -14,7 +14,7 @@ namespace System.Linq
             source is ICollection<TSource> collection ? new ValueTask<bool>(collection.Contains(value)) :
             ContainsAsync(source, value, comparer: null, cancellationToken);
 
-        public static ValueTask<bool> ContainsAsync<TSource>(this IAsyncEnumerable<TSource> source, TSource value, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<bool> ContainsAsync<TSource>(this IAsyncEnumerable<TSource> source, TSource value, IEqualityComparer<TSource>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));

+ 3 - 3
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/DefaultIfEmpty.cs

@@ -13,7 +13,7 @@ namespace System.Linq
     public static partial class AsyncEnumerable
     {
         public static IAsyncEnumerable<TSource> DefaultIfEmpty<TSource>(this IAsyncEnumerable<TSource> source) =>
-            DefaultIfEmpty(source, default);
+            DefaultIfEmpty(source, default!);
 
         public static IAsyncEnumerable<TSource> DefaultIfEmpty<TSource>(this IAsyncEnumerable<TSource> source, TSource defaultValue)
         {
@@ -28,7 +28,7 @@ namespace System.Linq
             private readonly IAsyncEnumerable<TSource> _source;
             private readonly TSource _defaultValue;
 
-            private IAsyncEnumerator<TSource> _enumerator;
+            private IAsyncEnumerator<TSource>? _enumerator;
 
             public DefaultIfEmptyAsyncIterator(IAsyncEnumerable<TSource> source, TSource defaultValue)
             {
@@ -76,7 +76,7 @@ namespace System.Linq
                         return true;
 
                     case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
+                        if (await _enumerator!.MoveNextAsync().ConfigureAwait(false))
                         {
                             _current = _enumerator.Current;
                             return true;

+ 7 - 7
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Distinct.cs

@@ -13,7 +13,7 @@ namespace System.Linq
     {
         public static IAsyncEnumerable<TSource> Distinct<TSource>(this IAsyncEnumerable<TSource> source) => Distinct(source, comparer: null);
 
-        public static IAsyncEnumerable<TSource> Distinct<TSource>(this IAsyncEnumerable<TSource> source, IEqualityComparer<TSource> comparer)
+        public static IAsyncEnumerable<TSource> Distinct<TSource>(this IAsyncEnumerable<TSource> source, IEqualityComparer<TSource>? comparer)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -23,13 +23,13 @@ namespace System.Linq
 
         private sealed class DistinctAsyncIterator<TSource> : AsyncIterator<TSource>, IAsyncIListProvider<TSource>
         {
-            private readonly IEqualityComparer<TSource> _comparer;
+            private readonly IEqualityComparer<TSource>? _comparer;
             private readonly IAsyncEnumerable<TSource> _source;
 
-            private IAsyncEnumerator<TSource> _enumerator;
-            private Set<TSource> _set;
+            private IAsyncEnumerator<TSource>? _enumerator;
+            private Set<TSource>? _set;
 
-            public DistinctAsyncIterator(IAsyncEnumerable<TSource> source, IEqualityComparer<TSource> comparer)
+            public DistinctAsyncIterator(IAsyncEnumerable<TSource> source, IEqualityComparer<TSource>? comparer)
             {
                 Debug.Assert(source != null);
 
@@ -103,10 +103,10 @@ namespace System.Linq
                         return true;
 
                     case AsyncIteratorState.Iterating:
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
+                        while (await _enumerator!.MoveNextAsync().ConfigureAwait(false))
                         {
                             element = _enumerator.Current;
-                            if (_set.Add(element))
+                            if (_set!.Add(element))
                             {
                                 _current = element;
                                 return true;

+ 1 - 1
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ElementAtOrDefault.cs

@@ -52,7 +52,7 @@ namespace System.Linq
                     }
                 }
 
-                return default;
+                return default!;
             }
         }
     }

+ 1 - 1
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Empty.cs

@@ -16,7 +16,7 @@ namespace System.Linq
         {
             public static readonly EmptyAsyncIterator<TValue> Instance = new EmptyAsyncIterator<TValue>();
 
-            public TValue Current => default;
+            public TValue Current => default!;
 
             public ValueTask<int> GetCountAsync(bool onlyIfCheap, CancellationToken cancellationToken) => new ValueTask<int>(0);
 

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

@@ -13,7 +13,7 @@ namespace System.Linq
         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)
+        public static IAsyncEnumerable<TSource> Except<TSource>(this IAsyncEnumerable<TSource> first, IAsyncEnumerable<TSource> second, IEqualityComparer<TSource>? comparer)
         {
             if (first == null)
                 throw Error.ArgumentNull(nameof(first));

+ 4 - 4
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/FirstOrDefault.cs

@@ -21,7 +21,7 @@ namespace System.Linq
             {
                 var first = await TryGetFirst(source, cancellationToken).ConfigureAwait(false);
 
-                return first.HasValue ? first.Value : default;
+                return first.HasValue ? first.Value : default!;
             }
         }
 
@@ -38,7 +38,7 @@ namespace System.Linq
             {
                 var first = await TryGetFirst(source, predicate, cancellationToken).ConfigureAwait(false);
 
-                return first.HasValue ? first.Value : default;
+                return first.HasValue ? first.Value : default!;
             }
         }
 
@@ -55,7 +55,7 @@ namespace System.Linq
             {
                 var first = await TryGetFirst(source, predicate, cancellationToken).ConfigureAwait(false);
 
-                return first.HasValue ? first.Value : default;
+                return first.HasValue ? first.Value : default!;
             }
         }
 
@@ -73,7 +73,7 @@ namespace System.Linq
             {
                 var first = await TryGetFirst(source, predicate, cancellationToken).ConfigureAwait(false);
 
-                return first.HasValue ? first.Value : default;
+                return first.HasValue ? first.Value : default!;
             }
         }
 #endif

+ 72 - 72
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/GroupBy.cs

@@ -13,80 +13,80 @@ namespace System.Linq
         public static IAsyncEnumerable<IAsyncGrouping<TKey, TSource>> GroupBy<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector) =>
             new GroupedAsyncEnumerable<TSource, TKey>(source, keySelector, comparer: null);
 
-        public static IAsyncEnumerable<IAsyncGrouping<TKey, TSource>> GroupBy<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer) =>
+        public static IAsyncEnumerable<IAsyncGrouping<TKey, TSource>> GroupBy<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer) =>
             new GroupedAsyncEnumerable<TSource, TKey>(source, keySelector, comparer);
 
         internal static IAsyncEnumerable<IAsyncGrouping<TKey, TSource>> GroupByAwaitCore<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector) =>
             new GroupedAsyncEnumerableWithTask<TSource, TKey>(source, keySelector, comparer: null);
 
-        internal static IAsyncEnumerable<IAsyncGrouping<TKey, TSource>> GroupByAwaitCore<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer) =>
+        internal static IAsyncEnumerable<IAsyncGrouping<TKey, TSource>> GroupByAwaitCore<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer) =>
             new GroupedAsyncEnumerableWithTask<TSource, TKey>(source, keySelector, comparer);
 
 #if !NO_DEEP_CANCELLATION
         internal static IAsyncEnumerable<IAsyncGrouping<TKey, TSource>> GroupByAwaitWithCancellationCore<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector) =>
             new GroupedAsyncEnumerableWithTaskAndCancellation<TSource, TKey>(source, keySelector, comparer: null);
 
-        internal static IAsyncEnumerable<IAsyncGrouping<TKey, TSource>> GroupByAwaitWithCancellationCore<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer) =>
+        internal static IAsyncEnumerable<IAsyncGrouping<TKey, TSource>> GroupByAwaitWithCancellationCore<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer) =>
             new GroupedAsyncEnumerableWithTaskAndCancellation<TSource, TKey>(source, keySelector, comparer);
 #endif
 
         public static IAsyncEnumerable<IAsyncGrouping<TKey, TElement>> GroupBy<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector) =>
             new GroupedAsyncEnumerable<TSource, TKey, TElement>(source, keySelector, elementSelector, comparer: null);
 
-        public static IAsyncEnumerable<IAsyncGrouping<TKey, TElement>> GroupBy<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer) =>
+        public static IAsyncEnumerable<IAsyncGrouping<TKey, TElement>> GroupBy<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey>? comparer) =>
             new GroupedAsyncEnumerable<TSource, TKey, TElement>(source, keySelector, elementSelector, comparer);
 
         internal static IAsyncEnumerable<IAsyncGrouping<TKey, TElement>> GroupByAwaitCore<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector) =>
             new GroupedAsyncEnumerableWithTask<TSource, TKey, TElement>(source, keySelector, elementSelector, comparer: null);
 
-        internal static IAsyncEnumerable<IAsyncGrouping<TKey, TElement>> GroupByAwaitCore<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer) =>
+        internal static IAsyncEnumerable<IAsyncGrouping<TKey, TElement>> GroupByAwaitCore<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey>? comparer) =>
             new GroupedAsyncEnumerableWithTask<TSource, TKey, TElement>(source, keySelector, elementSelector, comparer);
 
 #if !NO_DEEP_CANCELLATION
         internal static IAsyncEnumerable<IAsyncGrouping<TKey, TElement>> GroupByAwaitWithCancellationCore<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TSource, CancellationToken, ValueTask<TElement>> elementSelector) =>
             new GroupedAsyncEnumerableWithTaskAndCancellation<TSource, TKey, TElement>(source, keySelector, elementSelector, comparer: null);
 
-        internal static IAsyncEnumerable<IAsyncGrouping<TKey, TElement>> GroupByAwaitWithCancellationCore<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TSource, CancellationToken, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer) =>
+        internal static IAsyncEnumerable<IAsyncGrouping<TKey, TElement>> GroupByAwaitWithCancellationCore<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TSource, CancellationToken, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey>? comparer) =>
             new GroupedAsyncEnumerableWithTaskAndCancellation<TSource, TKey, TElement>(source, keySelector, elementSelector, comparer);
 #endif
 
         public static IAsyncEnumerable<TResult> GroupBy<TSource, TKey, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TKey, IAsyncEnumerable<TSource>, TResult> resultSelector) =>
             new GroupedResultAsyncEnumerable<TSource, TKey, TResult>(source, keySelector, resultSelector, comparer: null);
 
-        public static IAsyncEnumerable<TResult> GroupBy<TSource, TKey, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TKey, IAsyncEnumerable<TSource>, TResult> resultSelector, IEqualityComparer<TKey> comparer) =>
+        public static IAsyncEnumerable<TResult> GroupBy<TSource, TKey, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TKey, IAsyncEnumerable<TSource>, TResult> resultSelector, IEqualityComparer<TKey>? comparer) =>
             new GroupedResultAsyncEnumerable<TSource, TKey, TResult>(source, keySelector, resultSelector, comparer);
 
         internal static IAsyncEnumerable<TResult> GroupByAwaitCore<TSource, TKey, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TKey, IAsyncEnumerable<TSource>, ValueTask<TResult>> resultSelector) =>
             new GroupedResultAsyncEnumerableWithTask<TSource, TKey, TResult>(source, keySelector, resultSelector, comparer: null);
 
-        internal static IAsyncEnumerable<TResult> GroupByAwaitCore<TSource, TKey, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TKey, IAsyncEnumerable<TSource>, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer) =>
+        internal static IAsyncEnumerable<TResult> GroupByAwaitCore<TSource, TKey, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TKey, IAsyncEnumerable<TSource>, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey>? comparer) =>
             new GroupedResultAsyncEnumerableWithTask<TSource, TKey, TResult>(source, keySelector, resultSelector, comparer);
 
 #if !NO_DEEP_CANCELLATION
         internal static IAsyncEnumerable<TResult> GroupByAwaitWithCancellationCore<TSource, TKey, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TKey, IAsyncEnumerable<TSource>, CancellationToken, ValueTask<TResult>> resultSelector) =>
             new GroupedResultAsyncEnumerableWithTaskAndCancellation<TSource, TKey, TResult>(source, keySelector, resultSelector, comparer: null);
 
-        internal static IAsyncEnumerable<TResult> GroupByAwaitWithCancellationCore<TSource, TKey, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TKey, IAsyncEnumerable<TSource>, CancellationToken, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer) =>
+        internal static IAsyncEnumerable<TResult> GroupByAwaitWithCancellationCore<TSource, TKey, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TKey, IAsyncEnumerable<TSource>, CancellationToken, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey>? comparer) =>
             new GroupedResultAsyncEnumerableWithTaskAndCancellation<TSource, TKey, TResult>(source, keySelector, resultSelector, comparer);
 #endif
 
         public static IAsyncEnumerable<TResult> GroupBy<TSource, TKey, TElement, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, Func<TKey, IAsyncEnumerable<TElement>, TResult> resultSelector) =>
             new GroupedResultAsyncEnumerable<TSource, TKey, TElement, TResult>(source, keySelector, elementSelector, resultSelector, comparer: null);
 
-        public static IAsyncEnumerable<TResult> GroupBy<TSource, TKey, TElement, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, Func<TKey, IAsyncEnumerable<TElement>, TResult> resultSelector, IEqualityComparer<TKey> comparer) =>
+        public static IAsyncEnumerable<TResult> GroupBy<TSource, TKey, TElement, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, Func<TKey, IAsyncEnumerable<TElement>, TResult> resultSelector, IEqualityComparer<TKey>? comparer) =>
             new GroupedResultAsyncEnumerable<TSource, TKey, TElement, TResult>(source, keySelector, elementSelector, resultSelector, comparer);
 
         internal static IAsyncEnumerable<TResult> GroupByAwaitCore<TSource, TKey, TElement, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, Func<TKey, IAsyncEnumerable<TElement>, ValueTask<TResult>> resultSelector) =>
             new GroupedResultAsyncEnumerableWithTask<TSource, TKey, TElement, TResult>(source, keySelector, elementSelector, resultSelector, comparer: null);
 
-        internal static IAsyncEnumerable<TResult> GroupByAwaitCore<TSource, TKey, TElement, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, Func<TKey, IAsyncEnumerable<TElement>, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer) =>
+        internal static IAsyncEnumerable<TResult> GroupByAwaitCore<TSource, TKey, TElement, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, Func<TKey, IAsyncEnumerable<TElement>, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey>? comparer) =>
             new GroupedResultAsyncEnumerableWithTask<TSource, TKey, TElement, TResult>(source, keySelector, elementSelector, resultSelector, comparer);
 
 #if !NO_DEEP_CANCELLATION
         internal static IAsyncEnumerable<TResult> GroupByAwaitWithCancellationCore<TSource, TKey, TElement, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TSource, CancellationToken, ValueTask<TElement>> elementSelector, Func<TKey, IAsyncEnumerable<TElement>, CancellationToken, ValueTask<TResult>> resultSelector) =>
             new GroupedResultAsyncEnumerableWithTaskAndCancellation<TSource, TKey, TElement, TResult>(source, keySelector, elementSelector, resultSelector, comparer: null);
 
-        internal static IAsyncEnumerable<TResult> GroupByAwaitWithCancellationCore<TSource, TKey, TElement, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TSource, CancellationToken, ValueTask<TElement>> elementSelector, Func<TKey, IAsyncEnumerable<TElement>, CancellationToken, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer) =>
+        internal static IAsyncEnumerable<TResult> GroupByAwaitWithCancellationCore<TSource, TKey, TElement, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TSource, CancellationToken, ValueTask<TElement>> elementSelector, Func<TKey, IAsyncEnumerable<TElement>, CancellationToken, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey>? comparer) =>
             new GroupedResultAsyncEnumerableWithTaskAndCancellation<TSource, TKey, TElement, TResult>(source, keySelector, elementSelector, resultSelector, comparer);
 #endif
 
@@ -95,12 +95,12 @@ namespace System.Linq
             private readonly IAsyncEnumerable<TSource> _source;
             private readonly Func<TSource, TKey> _keySelector;
             private readonly Func<TKey, IAsyncEnumerable<TSource>, TResult> _resultSelector;
-            private readonly IEqualityComparer<TKey> _comparer;
+            private readonly IEqualityComparer<TKey>? _comparer;
 
-            private Internal.Lookup<TKey, TSource> _lookup;
-            private IEnumerator<TResult> _enumerator;
+            private Internal.Lookup<TKey, TSource>? _lookup;
+            private IEnumerator<TResult>? _enumerator;
 
-            public GroupedResultAsyncEnumerable(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TKey, IAsyncEnumerable<TSource>, TResult> resultSelector, IEqualityComparer<TKey> comparer)
+            public GroupedResultAsyncEnumerable(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TKey, IAsyncEnumerable<TSource>, TResult> resultSelector, IEqualityComparer<TKey>? comparer)
             {
                 _source = source ?? throw Error.ArgumentNull(nameof(source));
                 _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector));
@@ -136,7 +136,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        if (_enumerator.MoveNext())
+                        if (_enumerator!.MoveNext())
                         {
                             _current = _enumerator.Current;
                             return true;
@@ -184,12 +184,12 @@ namespace System.Linq
             private readonly IAsyncEnumerable<TSource> _source;
             private readonly Func<TSource, ValueTask<TKey>> _keySelector;
             private readonly Func<TKey, IAsyncEnumerable<TSource>, ValueTask<TResult>> _resultSelector;
-            private readonly IEqualityComparer<TKey> _comparer;
+            private readonly IEqualityComparer<TKey>? _comparer;
 
-            private Internal.LookupWithTask<TKey, TSource> _lookup;
-            private IAsyncEnumerator<TResult> _enumerator;
+            private Internal.LookupWithTask<TKey, TSource>? _lookup;
+            private IAsyncEnumerator<TResult>? _enumerator;
 
-            public GroupedResultAsyncEnumerableWithTask(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TKey, IAsyncEnumerable<TSource>, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer)
+            public GroupedResultAsyncEnumerableWithTask(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TKey, IAsyncEnumerable<TSource>, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey>? comparer)
             {
                 _source = source ?? throw Error.ArgumentNull(nameof(source));
                 _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector));
@@ -225,7 +225,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
+                        if (await _enumerator!.MoveNextAsync().ConfigureAwait(false))
                         {
                             _current = _enumerator.Current;
                             return true;
@@ -274,12 +274,12 @@ namespace System.Linq
             private readonly IAsyncEnumerable<TSource> _source;
             private readonly Func<TSource, CancellationToken, ValueTask<TKey>> _keySelector;
             private readonly Func<TKey, IAsyncEnumerable<TSource>, CancellationToken, ValueTask<TResult>> _resultSelector;
-            private readonly IEqualityComparer<TKey> _comparer;
+            private readonly IEqualityComparer<TKey>? _comparer;
 
-            private Internal.LookupWithTask<TKey, TSource> _lookup;
-            private IAsyncEnumerator<TResult> _enumerator;
+            private Internal.LookupWithTask<TKey, TSource>? _lookup;
+            private IAsyncEnumerator<TResult>? _enumerator;
 
-            public GroupedResultAsyncEnumerableWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TKey, IAsyncEnumerable<TSource>, CancellationToken, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer)
+            public GroupedResultAsyncEnumerableWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TKey, IAsyncEnumerable<TSource>, CancellationToken, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey>? comparer)
             {
                 _source = source ?? throw Error.ArgumentNull(nameof(source));
                 _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector));
@@ -315,7 +315,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
+                        if (await _enumerator!.MoveNextAsync().ConfigureAwait(false))
                         {
                             _current = _enumerator.Current;
                             return true;
@@ -365,12 +365,12 @@ namespace System.Linq
             private readonly Func<TSource, TKey> _keySelector;
             private readonly Func<TSource, TElement> _elementSelector;
             private readonly Func<TKey, IAsyncEnumerable<TElement>, TResult> _resultSelector;
-            private readonly IEqualityComparer<TKey> _comparer;
+            private readonly IEqualityComparer<TKey>? _comparer;
 
-            private Internal.Lookup<TKey, TElement> _lookup;
-            private IEnumerator<TResult> _enumerator;
+            private Internal.Lookup<TKey, TElement>? _lookup;
+            private IEnumerator<TResult>? _enumerator;
 
-            public GroupedResultAsyncEnumerable(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, Func<TKey, IAsyncEnumerable<TElement>, TResult> resultSelector, IEqualityComparer<TKey> comparer)
+            public GroupedResultAsyncEnumerable(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, Func<TKey, IAsyncEnumerable<TElement>, TResult> resultSelector, IEqualityComparer<TKey>? comparer)
             {
                 _source = source ?? throw Error.ArgumentNull(nameof(source));
                 _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector));
@@ -407,7 +407,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        if (_enumerator.MoveNext())
+                        if (_enumerator!.MoveNext())
                         {
                             _current = _enumerator.Current;
                             return true;
@@ -456,12 +456,12 @@ namespace System.Linq
             private readonly Func<TSource, ValueTask<TKey>> _keySelector;
             private readonly Func<TSource, ValueTask<TElement>> _elementSelector;
             private readonly Func<TKey, IAsyncEnumerable<TElement>, ValueTask<TResult>> _resultSelector;
-            private readonly IEqualityComparer<TKey> _comparer;
+            private readonly IEqualityComparer<TKey>? _comparer;
 
-            private Internal.LookupWithTask<TKey, TElement> _lookup;
-            private IAsyncEnumerator<TResult> _enumerator;
+            private Internal.LookupWithTask<TKey, TElement>? _lookup;
+            private IAsyncEnumerator<TResult>? _enumerator;
 
-            public GroupedResultAsyncEnumerableWithTask(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, Func<TKey, IAsyncEnumerable<TElement>, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer)
+            public GroupedResultAsyncEnumerableWithTask(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, Func<TKey, IAsyncEnumerable<TElement>, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey>? comparer)
             {
                 _source = source ?? throw Error.ArgumentNull(nameof(source));
                 _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector));
@@ -498,7 +498,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
+                        if (await _enumerator!.MoveNextAsync().ConfigureAwait(false))
                         {
                             _current = _enumerator.Current;
                             return true;
@@ -548,12 +548,12 @@ namespace System.Linq
             private readonly Func<TSource, CancellationToken, ValueTask<TKey>> _keySelector;
             private readonly Func<TSource, CancellationToken, ValueTask<TElement>> _elementSelector;
             private readonly Func<TKey, IAsyncEnumerable<TElement>, CancellationToken, ValueTask<TResult>> _resultSelector;
-            private readonly IEqualityComparer<TKey> _comparer;
+            private readonly IEqualityComparer<TKey>? _comparer;
 
-            private Internal.LookupWithTask<TKey, TElement> _lookup;
-            private IAsyncEnumerator<TResult> _enumerator;
+            private Internal.LookupWithTask<TKey, TElement>? _lookup;
+            private IAsyncEnumerator<TResult>? _enumerator;
 
-            public GroupedResultAsyncEnumerableWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TSource, CancellationToken, ValueTask<TElement>> elementSelector, Func<TKey, IAsyncEnumerable<TElement>, CancellationToken, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer)
+            public GroupedResultAsyncEnumerableWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TSource, CancellationToken, ValueTask<TElement>> elementSelector, Func<TKey, IAsyncEnumerable<TElement>, CancellationToken, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey>? comparer)
             {
                 _source = source ?? throw Error.ArgumentNull(nameof(source));
                 _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector));
@@ -590,7 +590,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
+                        if (await _enumerator!.MoveNextAsync().ConfigureAwait(false))
                         {
                             _current = _enumerator.Current;
                             return true;
@@ -639,12 +639,12 @@ namespace System.Linq
             private readonly IAsyncEnumerable<TSource> _source;
             private readonly Func<TSource, TKey> _keySelector;
             private readonly Func<TSource, TElement> _elementSelector;
-            private readonly IEqualityComparer<TKey> _comparer;
+            private readonly IEqualityComparer<TKey>? _comparer;
 
-            private Internal.Lookup<TKey, TElement> _lookup;
-            private IEnumerator<IGrouping<TKey, TElement>> _enumerator;
+            private Internal.Lookup<TKey, TElement>? _lookup;
+            private IEnumerator<IGrouping<TKey, TElement>>? _enumerator;
 
-            public GroupedAsyncEnumerable(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer)
+            public GroupedAsyncEnumerable(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey>? comparer)
             {
                 _source = source ?? throw Error.ArgumentNull(nameof(source));
                 _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector));
@@ -680,7 +680,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        if (_enumerator.MoveNext())
+                        if (_enumerator!.MoveNext())
                         {
                             _current = (IAsyncGrouping<TKey, TElement>)_enumerator.Current;
                             return true;
@@ -728,12 +728,12 @@ namespace System.Linq
             private readonly IAsyncEnumerable<TSource> _source;
             private readonly Func<TSource, ValueTask<TKey>> _keySelector;
             private readonly Func<TSource, ValueTask<TElement>> _elementSelector;
-            private readonly IEqualityComparer<TKey> _comparer;
+            private readonly IEqualityComparer<TKey>? _comparer;
 
-            private Internal.LookupWithTask<TKey, TElement> _lookup;
-            private IEnumerator<IGrouping<TKey, TElement>> _enumerator;
+            private Internal.LookupWithTask<TKey, TElement>? _lookup;
+            private IEnumerator<IGrouping<TKey, TElement>>? _enumerator;
 
-            public GroupedAsyncEnumerableWithTask(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer)
+            public GroupedAsyncEnumerableWithTask(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey>? comparer)
             {
                 _source = source ?? throw Error.ArgumentNull(nameof(source));
                 _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector));
@@ -769,7 +769,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        if (_enumerator.MoveNext())
+                        if (_enumerator!.MoveNext())
                         {
                             _current = (IAsyncGrouping<TKey, TElement>)_enumerator.Current;
                             return true;
@@ -818,12 +818,12 @@ namespace System.Linq
             private readonly IAsyncEnumerable<TSource> _source;
             private readonly Func<TSource, CancellationToken, ValueTask<TKey>> _keySelector;
             private readonly Func<TSource, CancellationToken, ValueTask<TElement>> _elementSelector;
-            private readonly IEqualityComparer<TKey> _comparer;
+            private readonly IEqualityComparer<TKey>? _comparer;
 
-            private Internal.LookupWithTask<TKey, TElement> _lookup;
-            private IEnumerator<IGrouping<TKey, TElement>> _enumerator;
+            private Internal.LookupWithTask<TKey, TElement>? _lookup;
+            private IEnumerator<IGrouping<TKey, TElement>>? _enumerator;
 
-            public GroupedAsyncEnumerableWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TSource, CancellationToken, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer)
+            public GroupedAsyncEnumerableWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TSource, CancellationToken, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey>? comparer)
             {
                 _source = source ?? throw Error.ArgumentNull(nameof(source));
                 _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector));
@@ -859,7 +859,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        if (_enumerator.MoveNext())
+                        if (_enumerator!.MoveNext())
                         {
                             _current = (IAsyncGrouping<TKey, TElement>)_enumerator.Current;
                             return true;
@@ -907,12 +907,12 @@ namespace System.Linq
         {
             private readonly IAsyncEnumerable<TSource> _source;
             private readonly Func<TSource, TKey> _keySelector;
-            private readonly IEqualityComparer<TKey> _comparer;
+            private readonly IEqualityComparer<TKey>? _comparer;
 
-            private Internal.Lookup<TKey, TSource> _lookup;
-            private IEnumerator<IGrouping<TKey, TSource>> _enumerator;
+            private Internal.Lookup<TKey, TSource>? _lookup;
+            private IEnumerator<IGrouping<TKey, TSource>>? _enumerator;
 
-            public GroupedAsyncEnumerable(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
+            public GroupedAsyncEnumerable(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer)
             {
                 _source = source ?? throw Error.ArgumentNull(nameof(source));
                 _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector));
@@ -947,7 +947,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        if (_enumerator.MoveNext())
+                        if (_enumerator!.MoveNext())
                         {
                             _current = (IAsyncGrouping<TKey, TSource>)_enumerator.Current;
                             return true;
@@ -994,12 +994,12 @@ namespace System.Linq
         {
             private readonly IAsyncEnumerable<TSource> _source;
             private readonly Func<TSource, ValueTask<TKey>> _keySelector;
-            private readonly IEqualityComparer<TKey> _comparer;
+            private readonly IEqualityComparer<TKey>? _comparer;
 
-            private Internal.LookupWithTask<TKey, TSource> _lookup;
-            private IEnumerator<IGrouping<TKey, TSource>> _enumerator;
+            private Internal.LookupWithTask<TKey, TSource>? _lookup;
+            private IEnumerator<IGrouping<TKey, TSource>>? _enumerator;
 
-            public GroupedAsyncEnumerableWithTask(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer)
+            public GroupedAsyncEnumerableWithTask(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer)
             {
                 _source = source ?? throw Error.ArgumentNull(nameof(source));
                 _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector));
@@ -1034,7 +1034,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        if (_enumerator.MoveNext())
+                        if (_enumerator!.MoveNext())
                         {
                             _current = (IAsyncGrouping<TKey, TSource>)_enumerator.Current;
                             return true;
@@ -1082,12 +1082,12 @@ namespace System.Linq
         {
             private readonly IAsyncEnumerable<TSource> _source;
             private readonly Func<TSource, CancellationToken, ValueTask<TKey>> _keySelector;
-            private readonly IEqualityComparer<TKey> _comparer;
+            private readonly IEqualityComparer<TKey>? _comparer;
 
-            private Internal.LookupWithTask<TKey, TSource> _lookup;
-            private IEnumerator<IGrouping<TKey, TSource>> _enumerator;
+            private Internal.LookupWithTask<TKey, TSource>? _lookup;
+            private IEnumerator<IGrouping<TKey, TSource>>? _enumerator;
 
-            public GroupedAsyncEnumerableWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer)
+            public GroupedAsyncEnumerableWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer)
             {
                 _source = source ?? throw Error.ArgumentNull(nameof(source));
                 _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector));
@@ -1122,7 +1122,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        if (_enumerator.MoveNext())
+                        if (_enumerator!.MoveNext())
                         {
                             _current = (IAsyncGrouping<TKey, TSource>)_enumerator.Current;
                             return true;

+ 3 - 3
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/GroupJoin.cs

@@ -13,7 +13,7 @@ namespace System.Linq
         public static IAsyncEnumerable<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IAsyncEnumerable<TInner>, TResult> resultSelector) =>
             GroupJoin(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer: null);
 
-        public static IAsyncEnumerable<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IAsyncEnumerable<TInner>, TResult> resultSelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncEnumerable<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IAsyncEnumerable<TInner>, TResult> resultSelector, IEqualityComparer<TKey>? comparer)
         {
             if (outer == null)
                 throw Error.ArgumentNull(nameof(outer));
@@ -51,7 +51,7 @@ namespace System.Linq
         internal static IAsyncEnumerable<TResult> GroupJoinAwaitCore<TOuter, TInner, TKey, TResult>(this IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, ValueTask<TKey>> outerKeySelector, Func<TInner, ValueTask<TKey>> innerKeySelector, Func<TOuter, IAsyncEnumerable<TInner>, ValueTask<TResult>> resultSelector) =>
             GroupJoinAwaitCore<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer: null);
 
-        internal static IAsyncEnumerable<TResult> GroupJoinAwaitCore<TOuter, TInner, TKey, TResult>(this IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, ValueTask<TKey>> outerKeySelector, Func<TInner, ValueTask<TKey>> innerKeySelector, Func<TOuter, IAsyncEnumerable<TInner>, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer)
+        internal static IAsyncEnumerable<TResult> GroupJoinAwaitCore<TOuter, TInner, TKey, TResult>(this IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, ValueTask<TKey>> outerKeySelector, Func<TInner, ValueTask<TKey>> innerKeySelector, Func<TOuter, IAsyncEnumerable<TInner>, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey>? comparer)
         {
             if (outer == null)
                 throw Error.ArgumentNull(nameof(outer));
@@ -90,7 +90,7 @@ namespace System.Linq
         internal static IAsyncEnumerable<TResult> GroupJoinAwaitWithCancellationCore<TOuter, TInner, TKey, TResult>(this IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, CancellationToken, ValueTask<TKey>> outerKeySelector, Func<TInner, CancellationToken, ValueTask<TKey>> innerKeySelector, Func<TOuter, IAsyncEnumerable<TInner>, CancellationToken, ValueTask<TResult>> resultSelector) =>
             GroupJoinAwaitWithCancellationCore<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer: null);
 
-        internal static IAsyncEnumerable<TResult> GroupJoinAwaitWithCancellationCore<TOuter, TInner, TKey, TResult>(this IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, CancellationToken, ValueTask<TKey>> outerKeySelector, Func<TInner, CancellationToken, ValueTask<TKey>> innerKeySelector, Func<TOuter, IAsyncEnumerable<TInner>, CancellationToken, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer)
+        internal static IAsyncEnumerable<TResult> GroupJoinAwaitWithCancellationCore<TOuter, TInner, TKey, TResult>(this IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, CancellationToken, ValueTask<TKey>> outerKeySelector, Func<TInner, CancellationToken, ValueTask<TKey>> innerKeySelector, Func<TOuter, IAsyncEnumerable<TInner>, CancellationToken, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey>? comparer)
         {
             if (outer == null)
                 throw Error.ArgumentNull(nameof(outer));

+ 9 - 1
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Grouping.cs

@@ -19,7 +19,15 @@ namespace System.Linq.Internal
         internal int _hashCode;
         internal Grouping<TKey, TElement> _hashNext;
         internal TKey _key;
-        internal Grouping<TKey, TElement> _next;
+        internal Grouping<TKey, TElement>? _next;
+
+        public Grouping(TKey key, int hashCode, TElement[] elements, Grouping<TKey, TElement> hashNext)
+        {
+            _key = key;
+            _hashCode = hashCode;
+            _elements = elements;
+            _hashNext = hashNext;
+        }
 
         IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
 

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

@@ -14,7 +14,7 @@ namespace System.Linq
         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)
+        public static IAsyncEnumerable<TSource> Intersect<TSource>(this IAsyncEnumerable<TSource> first, IAsyncEnumerable<TSource> second, IEqualityComparer<TSource>? comparer)
         {
             if (first == null)
                 throw Error.ArgumentNull(nameof(first));

+ 6 - 6
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Join.cs

@@ -14,7 +14,7 @@ namespace System.Linq
         public static IAsyncEnumerable<TResult> Join<TOuter, TInner, TKey, TResult>(this IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector) =>
             Join(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer: null);
 
-        public static IAsyncEnumerable<TResult> Join<TOuter, TInner, TKey, TResult>(this IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector, IEqualityComparer<TKey> comparer)
+        public static IAsyncEnumerable<TResult> Join<TOuter, TInner, TKey, TResult>(this IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector, IEqualityComparer<TKey>? comparer)
         {
             if (outer == null)
                 throw Error.ArgumentNull(nameof(outer));
@@ -45,7 +45,7 @@ namespace System.Linq
 
                                 var outerKey = outerKeySelector(item);
 
-                                var g = lookup.GetGrouping(outerKey, create: false);
+                                var g = lookup.GetGrouping(outerKey);
 
                                 if (g != null)
                                 {
@@ -68,7 +68,7 @@ namespace System.Linq
         internal static IAsyncEnumerable<TResult> JoinAwaitCore<TOuter, TInner, TKey, TResult>(this IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, ValueTask<TKey>> outerKeySelector, Func<TInner, ValueTask<TKey>> innerKeySelector, Func<TOuter, TInner, ValueTask<TResult>> resultSelector) =>
             JoinAwaitCore<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer: null);
 
-        internal static IAsyncEnumerable<TResult> JoinAwaitCore<TOuter, TInner, TKey, TResult>(this IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, ValueTask<TKey>> outerKeySelector, Func<TInner, ValueTask<TKey>> innerKeySelector, Func<TOuter, TInner, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer)
+        internal static IAsyncEnumerable<TResult> JoinAwaitCore<TOuter, TInner, TKey, TResult>(this IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, ValueTask<TKey>> outerKeySelector, Func<TInner, ValueTask<TKey>> innerKeySelector, Func<TOuter, TInner, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey>? comparer)
         {
             if (outer == null)
                 throw Error.ArgumentNull(nameof(outer));
@@ -99,7 +99,7 @@ namespace System.Linq
 
                                 var outerKey = await outerKeySelector(item).ConfigureAwait(false);
 
-                                var g = lookup.GetGrouping(outerKey, create: false);
+                                var g = lookup.GetGrouping(outerKey);
 
                                 if (g != null)
                                 {
@@ -123,7 +123,7 @@ namespace System.Linq
         internal static IAsyncEnumerable<TResult> JoinAwaitWithCancellationCore<TOuter, TInner, TKey, TResult>(this IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, CancellationToken, ValueTask<TKey>> outerKeySelector, Func<TInner, CancellationToken, ValueTask<TKey>> innerKeySelector, Func<TOuter, TInner, CancellationToken, ValueTask<TResult>> resultSelector) =>
             JoinAwaitWithCancellationCore<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer: null);
 
-        internal static IAsyncEnumerable<TResult> JoinAwaitWithCancellationCore<TOuter, TInner, TKey, TResult>(this IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, CancellationToken, ValueTask<TKey>> outerKeySelector, Func<TInner, CancellationToken, ValueTask<TKey>> innerKeySelector, Func<TOuter, TInner, CancellationToken, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer)
+        internal static IAsyncEnumerable<TResult> JoinAwaitWithCancellationCore<TOuter, TInner, TKey, TResult>(this IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, CancellationToken, ValueTask<TKey>> outerKeySelector, Func<TInner, CancellationToken, ValueTask<TKey>> innerKeySelector, Func<TOuter, TInner, CancellationToken, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey>? comparer)
         {
             if (outer == null)
                 throw Error.ArgumentNull(nameof(outer));
@@ -154,7 +154,7 @@ namespace System.Linq
 
                                 var outerKey = await outerKeySelector(item, cancellationToken).ConfigureAwait(false);
 
-                                var g = lookup.GetGrouping(outerKey, create: false);
+                                var g = lookup.GetGrouping(outerKey);
 
                                 if (g != null)
                                 {

+ 12 - 12
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/LastOrDefault.cs

@@ -21,7 +21,7 @@ namespace System.Linq
             {
                 var last = await TryGetLast(source, cancellationToken).ConfigureAwait(false);
 
-                return last.HasValue ? last.Value : default;
+                return last.HasValue ? last.Value : default!;
             }
         }
 
@@ -38,7 +38,7 @@ namespace System.Linq
             {
                 var last = await TryGetLast(source, predicate, cancellationToken).ConfigureAwait(false);
 
-                return last.HasValue ? last.Value : default;
+                return last.HasValue ? last.Value : default!;
             }
         }
 
@@ -55,7 +55,7 @@ namespace System.Linq
             {
                 var last = await TryGetLast(source, predicate, cancellationToken).ConfigureAwait(false);
 
-                return last.HasValue ? last.Value : default;
+                return last.HasValue ? last.Value : default!;
             }
         }
 
@@ -73,7 +73,7 @@ namespace System.Linq
             {
                 var last = await TryGetLast(source, predicate, cancellationToken).ConfigureAwait(false);
 
-                return last.HasValue ? last.Value : default;
+                return last.HasValue ? last.Value : default!;
             }
         }
 #endif
@@ -98,7 +98,7 @@ namespace System.Linq
 
                 static async ValueTask<Maybe<TSource>> Core(IAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
                 {
-                    var last = default(TSource);
+                    var last = default(TSource)!; // NB: Only matters when hasLast is set to true.
                     var hasLast = false;
 
                     await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false))
@@ -107,7 +107,7 @@ namespace System.Linq
                         last = item;
                     }
 
-                    return hasLast ? new Maybe<TSource>(last) : new Maybe<TSource>();
+                    return hasLast ? new Maybe<TSource>(last!) : new Maybe<TSource>();
                 }
             }
 
@@ -116,7 +116,7 @@ namespace System.Linq
 
         private static async ValueTask<Maybe<TSource>> TryGetLast<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate, CancellationToken cancellationToken)
         {
-            var last = default(TSource);
+            var last = default(TSource)!; // NB: Only matters when hasLast is set to true.
             var hasLast = false;
 
             await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false))
@@ -128,12 +128,12 @@ namespace System.Linq
                 }
             }
 
-            return hasLast ? new Maybe<TSource>(last) : new Maybe<TSource>();
+            return hasLast ? new Maybe<TSource>(last!) : new Maybe<TSource>();
         }
 
         private static async ValueTask<Maybe<TSource>> TryGetLast<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<bool>> predicate, CancellationToken cancellationToken)
         {
-            var last = default(TSource);
+            var last = default(TSource)!; // NB: Only matters when hasLast is set to true.
             var hasLast = false;
 
             await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false))
@@ -145,13 +145,13 @@ namespace System.Linq
                 }
             }
 
-            return hasLast ? new Maybe<TSource>(last) : new Maybe<TSource>();
+            return hasLast ? new Maybe<TSource>(last!) : new Maybe<TSource>();
         }
 
 #if !NO_DEEP_CANCELLATION
         private static async ValueTask<Maybe<TSource>> TryGetLast<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<bool>> predicate, CancellationToken cancellationToken)
         {
-            var last = default(TSource);
+            var last = default(TSource)!; // NB: Only matters when hasLast is set to true.
             var hasLast = false;
 
             await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false))
@@ -163,7 +163,7 @@ namespace System.Linq
                 }
             }
 
-            return hasLast ? new Maybe<TSource>(last) : new Maybe<TSource>();
+            return hasLast ? new Maybe<TSource>(last!) : new Maybe<TSource>();
         }
 #endif
     }

+ 121 - 105
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Lookup.cs

@@ -16,9 +16,9 @@ namespace System.Linq.Internal
     {
         private readonly IEqualityComparer<TKey> _comparer;
         private Grouping<TKey, TElement>[] _groupings;
-        private Grouping<TKey, TElement> _lastGrouping;
+        private Grouping<TKey, TElement>? _lastGrouping;
 
-        private Lookup(IEqualityComparer<TKey> comparer)
+        private Lookup(IEqualityComparer<TKey>? comparer)
         {
             _comparer = comparer ?? EqualityComparer<TKey>.Default;
             _groupings = new Grouping<TKey, TElement>[7];
@@ -30,7 +30,7 @@ namespace System.Linq.Internal
         {
             get
             {
-                var grouping = GetGrouping(key, create: false);
+                var grouping = GetGrouping(key);
                 if (grouping != null)
                 {
                     return grouping;
@@ -46,7 +46,7 @@ namespace System.Linq.Internal
 
         public bool Contains(TKey key)
         {
-            return GetGrouping(key, create: false) != null;
+            return GetGrouping(key) != null;
         }
 
         IEnumerator IEnumerable.GetEnumerator()
@@ -61,8 +61,8 @@ namespace System.Linq.Internal
             {
                 do
                 {
-                    g = g._next;
-                    yield return g;
+                    g = g!._next;
+                    yield return g!;
                 } while (g != _lastGrouping);
             }
         }
@@ -75,7 +75,7 @@ namespace System.Linq.Internal
                 do
                 {
                     g = g._next;
-                    g.Trim();
+                    g!.Trim();
 
                     var result = resultSelector(g._key, g._elements.ToAsyncEnumerable());
                     yield return result;
@@ -83,7 +83,7 @@ namespace System.Linq.Internal
             }
         }
 
-        internal static async Task<Lookup<TKey, TElement>> CreateAsync<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
+        internal static async Task<Lookup<TKey, TElement>> CreateAsync<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken)
         {
             Debug.Assert(source != null);
             Debug.Assert(keySelector != null);
@@ -94,7 +94,7 @@ namespace System.Linq.Internal
             await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false))
             {
                 var key = keySelector(item);
-                var group = lookup.GetGrouping(key, create: true);
+                var group = lookup.GetOrCreateGrouping(key);
 
                 var element = elementSelector(item);
                 group.Add(element);
@@ -103,7 +103,7 @@ namespace System.Linq.Internal
             return lookup;
         }
 
-        internal static async Task<Lookup<TKey, TElement>> CreateAsync(IAsyncEnumerable<TElement> source, Func<TElement, TKey> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
+        internal static async Task<Lookup<TKey, TElement>> CreateAsync(IAsyncEnumerable<TElement> source, Func<TElement, TKey> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken)
         {
             Debug.Assert(source != null);
             Debug.Assert(keySelector != null);
@@ -113,13 +113,13 @@ namespace System.Linq.Internal
             await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false))
             {
                 var key = keySelector(item);
-                lookup.GetGrouping(key, create: true).Add(item);
+                lookup.GetOrCreateGrouping(key).Add(item);
             }
 
             return lookup;
         }
 
-        internal static async Task<Lookup<TKey, TElement>> CreateForJoinAsync(IAsyncEnumerable<TElement> source, Func<TElement, TKey> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
+        internal static async Task<Lookup<TKey, TElement>> CreateForJoinAsync(IAsyncEnumerable<TElement> source, Func<TElement, TKey> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken)
         {
             var lookup = new Lookup<TKey, TElement>(comparer);
 
@@ -128,16 +128,22 @@ namespace System.Linq.Internal
                 var key = keySelector(item);
                 if (key != null)
                 {
-                    lookup.GetGrouping(key, create: true).Add(item);
+                    lookup.GetOrCreateGrouping(key).Add(item);
                 }
             }
 
             return lookup;
         }
 
-        internal Grouping<TKey, TElement> GetGrouping(TKey key, bool create)
+        internal Grouping<TKey, TElement>? GetGrouping(TKey key)
         {
             var hashCode = InternalGetHashCode(key);
+
+            return GetGrouping(key, hashCode);
+        }
+
+        internal Grouping<TKey, TElement>? GetGrouping(TKey key, int hashCode)
+        {
             for (var g = _groupings[hashCode % _groupings.Length]; g != null; g = g._hashNext)
             {
                 if (g._hashCode == hashCode && _comparer.Equals(g._key, key))
@@ -146,38 +152,40 @@ namespace System.Linq.Internal
                 }
             }
 
-            if (create)
+            return null;
+        }
+
+        internal Grouping<TKey, TElement> GetOrCreateGrouping(TKey key)
+        {
+            var hashCode = InternalGetHashCode(key);
+
+            var grouping = GetGrouping(key, hashCode);
+            if (grouping != null)
             {
-                if (Count == _groupings.Length)
-                {
-                    Resize();
-                }
+                return grouping;
+            }
 
-                var index = hashCode % _groupings.Length;
-                var g = new Grouping<TKey, TElement>
-                {
-                    _key = key,
-                    _hashCode = hashCode,
-                    _elements = new TElement[1],
-                    _hashNext = _groupings[index]
-                };
-                _groupings[index] = g;
-                if (_lastGrouping == null)
-                {
-                    g._next = g;
-                }
-                else
-                {
-                    g._next = _lastGrouping._next;
-                    _lastGrouping._next = g;
-                }
+            if (Count == _groupings.Length)
+            {
+                Resize();
+            }
 
-                _lastGrouping = g;
-                Count++;
-                return g;
+            var index = hashCode % _groupings.Length;
+            var g = new Grouping<TKey, TElement>(key, hashCode, new TElement[1], _groupings[index]);
+            _groupings[index] = g;
+            if (_lastGrouping == null)
+            {
+                g._next = g;
+            }
+            else
+            {
+                g._next = _lastGrouping._next;
+                _lastGrouping._next = g;
             }
 
-            return null;
+            _lastGrouping = g;
+            Count++;
+            return g;
         }
 
         internal int InternalGetHashCode(TKey key)
@@ -196,7 +204,7 @@ namespace System.Linq.Internal
                 do
                 {
                     g = g._next;
-                    g.Trim();
+                    g!.Trim();
                     array[index] = resultSelector(g._key, g._elements.ToAsyncEnumerable());
                     ++index;
                 } while (g != _lastGrouping);
@@ -214,7 +222,7 @@ namespace System.Linq.Internal
                 do
                 {
                     g = g._next;
-                    g.Trim();
+                    g!.Trim();
 
                     var result = resultSelector(g._key, g._elements.ToAsyncEnumerable());
                     list.Add(result);
@@ -231,8 +239,8 @@ namespace System.Linq.Internal
             var g = _lastGrouping;
             do
             {
-                g = g._next;
-                var index = g._hashCode % newSize;
+                g = g!._next;
+                var index = g!._hashCode % newSize;
                 g._hashNext = newGroupings[index];
                 newGroupings[index] = g;
             } while (g != _lastGrouping);
@@ -262,8 +270,8 @@ namespace System.Linq.Internal
             {
                 do
                 {
-                    g = g._next;
-                    list.Add(g);
+                    g = g!._next;
+                    list.Add(g!);
                 }
                 while (g != _lastGrouping);
             }
@@ -282,8 +290,8 @@ namespace System.Linq.Internal
             {
                 do
                 {
-                    g = g._next;
-                    array[index] = g;
+                    g = g!._next;
+                    array[index] = g!;
                     ++index;
                 }
                 while (g != _lastGrouping);
@@ -297,9 +305,9 @@ namespace System.Linq.Internal
     {
         private readonly IEqualityComparer<TKey> _comparer;
         private Grouping<TKey, TElement>[] _groupings;
-        private Grouping<TKey, TElement> _lastGrouping;
+        private Grouping<TKey, TElement>? _lastGrouping;
 
-        private LookupWithTask(IEqualityComparer<TKey> comparer)
+        private LookupWithTask(IEqualityComparer<TKey>? comparer)
         {
             _comparer = comparer ?? EqualityComparer<TKey>.Default;
             _groupings = new Grouping<TKey, TElement>[7];
@@ -311,7 +319,7 @@ namespace System.Linq.Internal
         {
             get
             {
-                var grouping = GetGrouping(key, create: false);
+                var grouping = GetGrouping(key);
                 if (grouping != null)
                 {
                     return grouping;
@@ -327,7 +335,7 @@ namespace System.Linq.Internal
 
         public bool Contains(TKey key)
         {
-            return GetGrouping(key, create: false) != null;
+            return GetGrouping(key) != null;
         }
 
         IEnumerator IEnumerable.GetEnumerator()
@@ -342,13 +350,13 @@ namespace System.Linq.Internal
             {
                 do
                 {
-                    g = g._next;
-                    yield return g;
+                    g = g!._next;
+                    yield return g!;
                 } while (g != _lastGrouping);
             }
         }
 
-        internal static async Task<LookupWithTask<TKey, TElement>> CreateAsync<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
+        internal static async Task<LookupWithTask<TKey, TElement>> CreateAsync<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken)
         {
             Debug.Assert(source != null);
             Debug.Assert(keySelector != null);
@@ -359,7 +367,7 @@ namespace System.Linq.Internal
             await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false))
             {
                 var key = await keySelector(item).ConfigureAwait(false);
-                var group = lookup.GetGrouping(key, create: true);
+                var group = lookup.GetOrCreateGrouping(key);
 
                 var element = await elementSelector(item).ConfigureAwait(false);
                 group.Add(element);
@@ -369,7 +377,7 @@ namespace System.Linq.Internal
         }
 
 #if !NO_DEEP_CANCELLATION
-        internal static async Task<LookupWithTask<TKey, TElement>> CreateAsync<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TSource, CancellationToken, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
+        internal static async Task<LookupWithTask<TKey, TElement>> CreateAsync<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TSource, CancellationToken, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken)
         {
             Debug.Assert(source != null);
             Debug.Assert(keySelector != null);
@@ -380,7 +388,7 @@ namespace System.Linq.Internal
             await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false))
             {
                 var key = await keySelector(item, cancellationToken).ConfigureAwait(false);
-                var group = lookup.GetGrouping(key, create: true);
+                var group = lookup.GetOrCreateGrouping(key);
 
                 var element = await elementSelector(item, cancellationToken).ConfigureAwait(false);
                 group.Add(element);
@@ -390,7 +398,7 @@ namespace System.Linq.Internal
         }
 #endif
 
-        internal static async Task<LookupWithTask<TKey, TElement>> CreateAsync(IAsyncEnumerable<TElement> source, Func<TElement, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
+        internal static async Task<LookupWithTask<TKey, TElement>> CreateAsync(IAsyncEnumerable<TElement> source, Func<TElement, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken)
         {
             Debug.Assert(source != null);
             Debug.Assert(keySelector != null);
@@ -400,14 +408,14 @@ namespace System.Linq.Internal
             await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false))
             {
                 var key = await keySelector(item).ConfigureAwait(false);
-                lookup.GetGrouping(key, create: true).Add(item);
+                lookup.GetOrCreateGrouping(key).Add(item);
             }
 
             return lookup;
         }
 
 #if !NO_DEEP_CANCELLATION
-        internal static async Task<LookupWithTask<TKey, TElement>> CreateAsync(IAsyncEnumerable<TElement> source, Func<TElement, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
+        internal static async Task<LookupWithTask<TKey, TElement>> CreateAsync(IAsyncEnumerable<TElement> source, Func<TElement, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken)
         {
             Debug.Assert(source != null);
             Debug.Assert(keySelector != null);
@@ -417,14 +425,14 @@ namespace System.Linq.Internal
             await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false))
             {
                 var key = await keySelector(item, cancellationToken).ConfigureAwait(false);
-                lookup.GetGrouping(key, create: true).Add(item);
+                lookup.GetOrCreateGrouping(key).Add(item);
             }
 
             return lookup;
         }
 #endif
 
-        internal static async Task<LookupWithTask<TKey, TElement>> CreateForJoinAsync(IAsyncEnumerable<TElement> source, Func<TElement, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
+        internal static async Task<LookupWithTask<TKey, TElement>> CreateForJoinAsync(IAsyncEnumerable<TElement> source, Func<TElement, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken)
         {
             var lookup = new LookupWithTask<TKey, TElement>(comparer);
 
@@ -433,7 +441,7 @@ namespace System.Linq.Internal
                 var key = await keySelector(item).ConfigureAwait(false);
                 if (key != null)
                 {
-                    lookup.GetGrouping(key, create: true).Add(item);
+                    lookup.GetOrCreateGrouping(key).Add(item);
                 }
             }
 
@@ -441,7 +449,7 @@ namespace System.Linq.Internal
         }
 
 #if !NO_DEEP_CANCELLATION
-        internal static async Task<LookupWithTask<TKey, TElement>> CreateForJoinAsync(IAsyncEnumerable<TElement> source, Func<TElement, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
+        internal static async Task<LookupWithTask<TKey, TElement>> CreateForJoinAsync(IAsyncEnumerable<TElement> source, Func<TElement, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken)
         {
             var lookup = new LookupWithTask<TKey, TElement>(comparer);
 
@@ -450,7 +458,7 @@ namespace System.Linq.Internal
                 var key = await keySelector(item, cancellationToken).ConfigureAwait(false);
                 if (key != null)
                 {
-                    lookup.GetGrouping(key, create: true).Add(item);
+                    lookup.GetOrCreateGrouping(key).Add(item);
                 }
             }
 
@@ -458,9 +466,15 @@ namespace System.Linq.Internal
         }
 #endif
 
-        internal Grouping<TKey, TElement> GetGrouping(TKey key, bool create)
+        internal Grouping<TKey, TElement>? GetGrouping(TKey key)
         {
             var hashCode = InternalGetHashCode(key);
+
+            return GetGrouping(key, hashCode);
+        }
+
+        internal Grouping<TKey, TElement>? GetGrouping(TKey key, int hashCode)
+        {
             for (var g = _groupings[hashCode % _groupings.Length]; g != null; g = g._hashNext)
             {
                 if (g._hashCode == hashCode && _comparer.Equals(g._key, key))
@@ -469,38 +483,40 @@ namespace System.Linq.Internal
                 }
             }
 
-            if (create)
+            return null;
+        }
+
+        internal Grouping<TKey, TElement> GetOrCreateGrouping(TKey key)
+        {
+            var hashCode = InternalGetHashCode(key);
+
+            var grouping = GetGrouping(key, hashCode);
+            if (grouping != null)
             {
-                if (Count == _groupings.Length)
-                {
-                    Resize();
-                }
+                return grouping;
+            }
 
-                var index = hashCode % _groupings.Length;
-                var g = new Grouping<TKey, TElement>
-                {
-                    _key = key,
-                    _hashCode = hashCode,
-                    _elements = new TElement[1],
-                    _hashNext = _groupings[index]
-                };
-                _groupings[index] = g;
-                if (_lastGrouping == null)
-                {
-                    g._next = g;
-                }
-                else
-                {
-                    g._next = _lastGrouping._next;
-                    _lastGrouping._next = g;
-                }
+            if (Count == _groupings.Length)
+            {
+                Resize();
+            }
 
-                _lastGrouping = g;
-                Count++;
-                return g;
+            var index = hashCode % _groupings.Length;
+            var g = new Grouping<TKey, TElement>(key, hashCode, new TElement[1], _groupings[index]);
+            _groupings[index] = g;
+            if (_lastGrouping == null)
+            {
+                g._next = g;
+            }
+            else
+            {
+                g._next = _lastGrouping._next;
+                _lastGrouping._next = g;
             }
 
-            return null;
+            _lastGrouping = g;
+            Count++;
+            return g;
         }
 
         internal int InternalGetHashCode(TKey key)
@@ -519,7 +535,7 @@ namespace System.Linq.Internal
                 do
                 {
                     g = g._next;
-                    g.Trim();
+                    g!.Trim();
                     array[index] = await resultSelector(g._key, g._elements.ToAsyncEnumerable()).ConfigureAwait(false);
                     ++index;
                 } while (g != _lastGrouping);
@@ -541,7 +557,7 @@ namespace System.Linq.Internal
                 do
                 {
                     g = g._next;
-                    g.Trim();
+                    g!.Trim();
                     array[index] = await resultSelector(g._key, g._elements.ToAsyncEnumerable(), cancellationToken).ConfigureAwait(false);
                     ++index;
                 } while (g != _lastGrouping);
@@ -560,7 +576,7 @@ namespace System.Linq.Internal
                 do
                 {
                     g = g._next;
-                    g.Trim();
+                    g!.Trim();
 
                     var result = await resultSelector(g._key, g._elements.ToAsyncEnumerable()).ConfigureAwait(false);
                     list.Add(result);
@@ -582,7 +598,7 @@ namespace System.Linq.Internal
                 do
                 {
                     g = g._next;
-                    g.Trim();
+                    g!.Trim();
 
                     var result = await resultSelector(g._key, g._elements.ToAsyncEnumerable(), cancellationToken).ConfigureAwait(false);
                     list.Add(result);
@@ -600,8 +616,8 @@ namespace System.Linq.Internal
             var g = _lastGrouping;
             do
             {
-                g = g._next;
-                var index = g._hashCode % newSize;
+                g = g!._next;
+                var index = g!._hashCode % newSize;
                 g._hashNext = newGroupings[index];
                 newGroupings[index] = g;
             } while (g != _lastGrouping);
@@ -631,8 +647,8 @@ namespace System.Linq.Internal
             {
                 do
                 {
-                    g = g._next;
-                    list.Add(g);
+                    g = g!._next;
+                    list.Add(g!);
                 }
                 while (g != _lastGrouping);
             }
@@ -651,8 +667,8 @@ namespace System.Linq.Internal
             {
                 do
                 {
-                    g = g._next;
-                    array[index] = g;
+                    g = g!._next;
+                    array[index] = g!;
                     ++index;
                 }
                 while (g != _lastGrouping);

+ 16 - 16
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Max.cs

@@ -15,7 +15,7 @@ namespace System.Linq
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
 
-            if (default(TSource) == null)
+            if (default(TSource)! == null) // NB: Null value is desired; JIT-time check.
             {
                 return Core(source, cancellationToken);
 
@@ -23,7 +23,7 @@ namespace System.Linq
                 {
                     var comparer = Comparer<TSource>.Default;
 
-                    var value = default(TSource);
+                    TSource value;
 
                     await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
                     {
@@ -31,7 +31,7 @@ namespace System.Linq
                         {
                             if (!await e.MoveNextAsync())
                             {
-                                return value;
+                                return default!;
                             }
 
                             value = e.Current;
@@ -60,7 +60,7 @@ namespace System.Linq
                 {
                     var comparer = Comparer<TSource>.Default;
 
-                    var value = default(TSource);
+                    TSource value;
 
                     await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
                     {
@@ -93,7 +93,7 @@ namespace System.Linq
             if (selector == null)
                 throw Error.ArgumentNull(nameof(selector));
 
-            if (default(TResult) == null)
+            if (default(TResult)! == null) // NB: Null value is desired; JIT-time check.
             {
                 return Core(source, selector, cancellationToken);
 
@@ -101,7 +101,7 @@ namespace System.Linq
                 {
                     var comparer = Comparer<TResult>.Default;
 
-                    var value = default(TResult);
+                    TResult value;
 
                     await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
                     {
@@ -109,7 +109,7 @@ namespace System.Linq
                         {
                             if (!await e.MoveNextAsync())
                             {
-                                return value;
+                                return default!;
                             }
 
                             value = selector(e.Current);
@@ -138,7 +138,7 @@ namespace System.Linq
                 {
                     var comparer = Comparer<TResult>.Default;
 
-                    var value = default(TResult);
+                    TResult value;
 
                     await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
                     {
@@ -171,7 +171,7 @@ namespace System.Linq
             if (selector == null)
                 throw Error.ArgumentNull(nameof(selector));
 
-            if (default(TResult) == null)
+            if (default(TResult)! == null) // NB: Null value is desired; JIT-time check.
             {
                 return Core(source, selector, cancellationToken);
 
@@ -179,7 +179,7 @@ namespace System.Linq
                 {
                     var comparer = Comparer<TResult>.Default;
 
-                    var value = default(TResult);
+                    TResult value;
 
                     await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
                     {
@@ -187,7 +187,7 @@ namespace System.Linq
                         {
                             if (!await e.MoveNextAsync())
                             {
-                                return value;
+                                return default!;
                             }
 
                             value = await selector(e.Current).ConfigureAwait(false);
@@ -216,7 +216,7 @@ namespace System.Linq
                 {
                     var comparer = Comparer<TResult>.Default;
 
-                    var value = default(TResult);
+                    TResult value;
 
                     await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
                     {
@@ -251,7 +251,7 @@ namespace System.Linq
             if (selector == null)
                 throw Error.ArgumentNull(nameof(selector));
 
-            if (default(TResult) == null)
+            if (default(TResult)! == null) // NB: Null value is desired; JIT-time check.
             {
                 return Core(source, selector, cancellationToken);
 
@@ -259,7 +259,7 @@ namespace System.Linq
                 {
                     var comparer = Comparer<TResult>.Default;
 
-                    var value = default(TResult);
+                    TResult value;
 
                     await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
                     {
@@ -267,7 +267,7 @@ namespace System.Linq
                         {
                             if (!await e.MoveNextAsync())
                             {
-                                return value;
+                                return default!;
                             }
 
                             value = await selector(e.Current, cancellationToken).ConfigureAwait(false);
@@ -296,7 +296,7 @@ namespace System.Linq
                 {
                     var comparer = Comparer<TResult>.Default;
 
-                    var value = default(TResult);
+                    TResult value;
 
                     await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
                     {

+ 16 - 16
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Min.cs

@@ -15,7 +15,7 @@ namespace System.Linq
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
 
-            if (default(TSource) == null)
+            if (default(TSource)! == null) // NB: Null value is desired; JIT-time check.
             {
                 return Core(source, cancellationToken);
 
@@ -23,7 +23,7 @@ namespace System.Linq
                 {
                     var comparer = Comparer<TSource>.Default;
 
-                    var value = default(TSource);
+                    TSource value;
 
                     await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
                     {
@@ -31,7 +31,7 @@ namespace System.Linq
                         {
                             if (!await e.MoveNextAsync())
                             {
-                                return value;
+                                return default!;
                             }
 
                             value = e.Current;
@@ -60,7 +60,7 @@ namespace System.Linq
                 {
                     var comparer = Comparer<TSource>.Default;
 
-                    var value = default(TSource);
+                    TSource value;
 
                     await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
                     {
@@ -94,7 +94,7 @@ namespace System.Linq
             if (selector == null)
                 throw Error.ArgumentNull(nameof(selector));
 
-            if (default(TResult) == null)
+            if (default(TResult)! == null) // NB: Null value is desired; JIT-time check.
             {
                 return Core(source, selector, cancellationToken);
 
@@ -102,7 +102,7 @@ namespace System.Linq
                 {
                     var comparer = Comparer<TResult>.Default;
 
-                    var value = default(TResult);
+                    TResult value;
 
                     await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
                     {
@@ -110,7 +110,7 @@ namespace System.Linq
                         {
                             if (!await e.MoveNextAsync())
                             {
-                                return value;
+                                return default!;
                             }
 
                             value = selector(e.Current);
@@ -139,7 +139,7 @@ namespace System.Linq
                 {
                     var comparer = Comparer<TResult>.Default;
 
-                    var value = default(TResult);
+                    TResult value;
 
                     await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
                     {
@@ -173,7 +173,7 @@ namespace System.Linq
             if (selector == null)
                 throw Error.ArgumentNull(nameof(selector));
 
-            if (default(TResult) == null)
+            if (default(TResult)! == null) // NB: Null value is desired; JIT-time check.
             {
                 return Core(source, selector, cancellationToken);
 
@@ -181,7 +181,7 @@ namespace System.Linq
                 {
                     var comparer = Comparer<TResult>.Default;
 
-                    var value = default(TResult);
+                    TResult value;
 
                     await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
                     {
@@ -189,7 +189,7 @@ namespace System.Linq
                         {
                             if (!await e.MoveNextAsync())
                             {
-                                return value;
+                                return default!;
                             }
 
                             value = await selector(e.Current).ConfigureAwait(false);
@@ -218,7 +218,7 @@ namespace System.Linq
                 {
                     var comparer = Comparer<TResult>.Default;
 
-                    var value = default(TResult);
+                    TResult value;
 
                     await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
                     {
@@ -253,7 +253,7 @@ namespace System.Linq
             if (selector == null)
                 throw Error.ArgumentNull(nameof(selector));
 
-            if (default(TResult) == null)
+            if (default(TResult)! == null) // NB: Null value is desired; JIT-time check.
             {
                 return Core(source, selector, cancellationToken);
 
@@ -261,7 +261,7 @@ namespace System.Linq
                 {
                     var comparer = Comparer<TResult>.Default;
 
-                    var value = default(TResult);
+                    TResult value;
 
                     await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
                     {
@@ -269,7 +269,7 @@ namespace System.Linq
                         {
                             if (!await e.MoveNextAsync())
                             {
-                                return value;
+                                return default!;
                             }
 
                             value = await selector(e.Current, cancellationToken).ConfigureAwait(false);
@@ -298,7 +298,7 @@ namespace System.Linq
                 {
                     var comparer = Comparer<TResult>.Default;
 
-                    var value = default(TResult);
+                    TResult value;
 
                     await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
                     {

+ 34 - 31
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/OrderedAsyncEnumerable.cs

@@ -15,8 +15,8 @@ namespace System.Linq
     {
         protected readonly IAsyncEnumerable<TElement> _source;
 
-        private TElement[] _buffer;
-        private int[] _indexes;
+        private TElement[]? _buffer;
+        private int[]? _indexes;
         private int _index;
 
         protected OrderedAsyncEnumerable(IAsyncEnumerable<TElement> source)
@@ -24,17 +24,17 @@ namespace System.Linq
             _source = source ?? throw Error.ArgumentNull(nameof(source));
         }
 
-        IOrderedAsyncEnumerable<TElement> IOrderedAsyncEnumerable<TElement>.CreateOrderedEnumerable<TKey>(Func<TElement, TKey> keySelector, IComparer<TKey> comparer, bool descending)
+        IOrderedAsyncEnumerable<TElement> IOrderedAsyncEnumerable<TElement>.CreateOrderedEnumerable<TKey>(Func<TElement, TKey> keySelector, IComparer<TKey>? comparer, bool descending)
         {
             return new OrderedAsyncEnumerable<TElement, TKey>(_source, keySelector, comparer, descending, this);
         }
 
-        IOrderedAsyncEnumerable<TElement> IOrderedAsyncEnumerable<TElement>.CreateOrderedEnumerable<TKey>(Func<TElement, ValueTask<TKey>> keySelector, IComparer<TKey> comparer, bool descending)
+        IOrderedAsyncEnumerable<TElement> IOrderedAsyncEnumerable<TElement>.CreateOrderedEnumerable<TKey>(Func<TElement, ValueTask<TKey>> keySelector, IComparer<TKey>? comparer, bool descending)
         {
             return new OrderedAsyncEnumerableWithTask<TElement, TKey>(_source, keySelector, comparer, descending, this);
         }
 
-        IOrderedAsyncEnumerable<TElement> IOrderedAsyncEnumerable<TElement>.CreateOrderedEnumerable<TKey>(Func<TElement, CancellationToken, ValueTask<TKey>> keySelector, IComparer<TKey> comparer, bool descending)
+        IOrderedAsyncEnumerable<TElement> IOrderedAsyncEnumerable<TElement>.CreateOrderedEnumerable<TKey>(Func<TElement, CancellationToken, ValueTask<TKey>> keySelector, IComparer<TKey>? comparer, bool descending)
         {
             return new OrderedAsyncEnumerableWithTaskAndCancellation<TElement, TKey>(_source, keySelector, comparer, descending, this);
         }
@@ -54,9 +54,9 @@ namespace System.Linq
                     goto case AsyncIteratorState.Iterating;
 
                 case AsyncIteratorState.Iterating:
-                    if (_index < _buffer.Length)
+                    if (_index < _buffer!.Length)
                     {
-                        _current = _buffer[_indexes[_index++]];
+                        _current = _buffer[_indexes![_index++]];
                         return true;
                     }
 
@@ -75,7 +75,7 @@ namespace System.Linq
             await base.DisposeAsync().ConfigureAwait(false);
         }
 
-        internal abstract AsyncEnumerableSorter<TElement> GetAsyncEnumerableSorter(AsyncEnumerableSorter<TElement> next, CancellationToken cancellationToken);
+        internal abstract AsyncEnumerableSorter<TElement> GetAsyncEnumerableSorter(AsyncEnumerableSorter<TElement>? next, CancellationToken cancellationToken);
 
         internal AsyncEnumerableSorter<TElement> GetAsyncEnumerableSorter(CancellationToken cancellationToken) => GetAsyncEnumerableSorter(next: null, cancellationToken);
 
@@ -260,7 +260,7 @@ namespace System.Linq
 
         private AsyncCachingComparer<TElement> GetComparer() => GetComparer(childComparer: null);
 
-        internal abstract AsyncCachingComparer<TElement> GetComparer(AsyncCachingComparer<TElement> childComparer);
+        internal abstract AsyncCachingComparer<TElement> GetComparer(AsyncCachingComparer<TElement>? childComparer);
 
         public async ValueTask<Maybe<TElement>> TryGetFirstAsync(CancellationToken cancellationToken)
         {
@@ -413,9 +413,9 @@ namespace System.Linq
         private readonly IComparer<TKey> _comparer;
         private readonly bool _descending;
         private readonly Func<TElement, TKey> _keySelector;
-        private readonly OrderedAsyncEnumerable<TElement> _parent;
+        private readonly OrderedAsyncEnumerable<TElement>? _parent;
 
-        public OrderedAsyncEnumerable(IAsyncEnumerable<TElement> source, Func<TElement, TKey> keySelector, IComparer<TKey> comparer, bool descending, OrderedAsyncEnumerable<TElement> parent)
+        public OrderedAsyncEnumerable(IAsyncEnumerable<TElement> source, Func<TElement, TKey> keySelector, IComparer<TKey>? comparer, bool descending, OrderedAsyncEnumerable<TElement>? parent)
             : base(source)
         {
             _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector));
@@ -429,7 +429,7 @@ namespace System.Linq
             return new OrderedAsyncEnumerable<TElement, TKey>(_source, _keySelector, _comparer, _descending, _parent);
         }
 
-        internal override AsyncEnumerableSorter<TElement> GetAsyncEnumerableSorter(AsyncEnumerableSorter<TElement> next, CancellationToken cancellationToken)
+        internal override AsyncEnumerableSorter<TElement> GetAsyncEnumerableSorter(AsyncEnumerableSorter<TElement>? next, CancellationToken cancellationToken)
         {
             var sorter = new SyncKeySelectorAsyncEnumerableSorter<TElement, TKey>(_keySelector, _comparer, _descending, next);
 
@@ -441,7 +441,7 @@ namespace System.Linq
             return sorter;
         }
 
-        internal override AsyncCachingComparer<TElement> GetComparer(AsyncCachingComparer<TElement> childComparer)
+        internal override AsyncCachingComparer<TElement> GetComparer(AsyncCachingComparer<TElement>? childComparer)
         {
             AsyncCachingComparer<TElement> cmp = childComparer == null
                 ? new AsyncCachingComparer<TElement, TKey>(_keySelector, _comparer, _descending)
@@ -456,9 +456,9 @@ namespace System.Linq
         private readonly IComparer<TKey> _comparer;
         private readonly bool _descending;
         private readonly Func<TElement, ValueTask<TKey>> _keySelector;
-        private readonly OrderedAsyncEnumerable<TElement> _parent;
+        private readonly OrderedAsyncEnumerable<TElement>? _parent;
 
-        public OrderedAsyncEnumerableWithTask(IAsyncEnumerable<TElement> source, Func<TElement, ValueTask<TKey>> keySelector, IComparer<TKey> comparer, bool descending, OrderedAsyncEnumerable<TElement> parent)
+        public OrderedAsyncEnumerableWithTask(IAsyncEnumerable<TElement> source, Func<TElement, ValueTask<TKey>> keySelector, IComparer<TKey>? comparer, bool descending, OrderedAsyncEnumerable<TElement>? parent)
             : base(source)
         {
             _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector));
@@ -472,7 +472,7 @@ namespace System.Linq
             return new OrderedAsyncEnumerableWithTask<TElement, TKey>(_source, _keySelector, _comparer, _descending, _parent);
         }
 
-        internal override AsyncEnumerableSorter<TElement> GetAsyncEnumerableSorter(AsyncEnumerableSorter<TElement> next, CancellationToken cancellationToken)
+        internal override AsyncEnumerableSorter<TElement> GetAsyncEnumerableSorter(AsyncEnumerableSorter<TElement>? next, CancellationToken cancellationToken)
         {
             var sorter = new AsyncKeySelectorAsyncEnumerableSorter<TElement, TKey>(_keySelector, _comparer, _descending, next);
 
@@ -484,7 +484,7 @@ namespace System.Linq
             return sorter;
         }
 
-        internal override AsyncCachingComparer<TElement> GetComparer(AsyncCachingComparer<TElement> childComparer)
+        internal override AsyncCachingComparer<TElement> GetComparer(AsyncCachingComparer<TElement>? childComparer)
         {
             AsyncCachingComparer<TElement> cmp = childComparer == null
                 ? new AsyncCachingComparerWithTask<TElement, TKey>(_keySelector, _comparer, _descending)
@@ -500,9 +500,9 @@ namespace System.Linq
         private readonly IComparer<TKey> _comparer;
         private readonly bool _descending;
         private readonly Func<TElement, CancellationToken, ValueTask<TKey>> _keySelector;
-        private readonly OrderedAsyncEnumerable<TElement> _parent;
+        private readonly OrderedAsyncEnumerable<TElement>? _parent;
 
-        public OrderedAsyncEnumerableWithTaskAndCancellation(IAsyncEnumerable<TElement> source, Func<TElement, CancellationToken, ValueTask<TKey>> keySelector, IComparer<TKey> comparer, bool descending, OrderedAsyncEnumerable<TElement> parent)
+        public OrderedAsyncEnumerableWithTaskAndCancellation(IAsyncEnumerable<TElement> source, Func<TElement, CancellationToken, ValueTask<TKey>> keySelector, IComparer<TKey>? comparer, bool descending, OrderedAsyncEnumerable<TElement>? parent)
             : base(source)
         {
             _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector));
@@ -516,7 +516,7 @@ namespace System.Linq
             return new OrderedAsyncEnumerableWithTaskAndCancellation<TElement, TKey>(_source, _keySelector, _comparer, _descending, _parent);
         }
 
-        internal override AsyncEnumerableSorter<TElement> GetAsyncEnumerableSorter(AsyncEnumerableSorter<TElement> next, CancellationToken cancellationToken)
+        internal override AsyncEnumerableSorter<TElement> GetAsyncEnumerableSorter(AsyncEnumerableSorter<TElement>? next, CancellationToken cancellationToken)
         {
             var sorter = new AsyncKeySelectorAsyncEnumerableSorterWithCancellation<TElement, TKey>(_keySelector, _comparer, _descending, next, cancellationToken);
 
@@ -528,7 +528,7 @@ namespace System.Linq
             return sorter;
         }
 
-        internal override AsyncCachingComparer<TElement> GetComparer(AsyncCachingComparer<TElement> childComparer)
+        internal override AsyncCachingComparer<TElement> GetComparer(AsyncCachingComparer<TElement>? childComparer)
         {
             AsyncCachingComparer<TElement> cmp = childComparer == null
                 ? new AsyncCachingComparerWithTaskAndCancellation<TElement, TKey>(_keySelector, _comparer, _descending)
@@ -599,10 +599,10 @@ namespace System.Linq
     {
         private readonly IComparer<TKey> _comparer;
         private readonly bool _descending;
-        protected readonly AsyncEnumerableSorter<TElement> _next;
-        protected TKey[] _keys;
+        protected readonly AsyncEnumerableSorter<TElement>? _next;
+        protected TKey[]? _keys;
 
-        public AsyncEnumerableSorterBase(IComparer<TKey> comparer, bool descending, AsyncEnumerableSorter<TElement> next)
+        public AsyncEnumerableSorterBase(IComparer<TKey> comparer, bool descending, AsyncEnumerableSorter<TElement>? next)
         {
             _comparer = comparer;
             _descending = descending;
@@ -611,7 +611,7 @@ namespace System.Linq
 
         internal sealed override int CompareAnyKeys(int index1, int index2)
         {
-            var c = _comparer.Compare(_keys[index1], _keys[index2]);
+            var c = _comparer.Compare(_keys![index1], _keys[index2]); // NB: _keys is assigned before calling this method.
 
             if (c == 0)
             {
@@ -783,7 +783,7 @@ namespace System.Linq
     {
         private readonly Func<TElement, TKey> _keySelector;
 
-        public SyncKeySelectorAsyncEnumerableSorter(Func<TElement, TKey> keySelector, IComparer<TKey> comparer, bool descending, AsyncEnumerableSorter<TElement> next)
+        public SyncKeySelectorAsyncEnumerableSorter(Func<TElement, TKey> keySelector, IComparer<TKey> comparer, bool descending, AsyncEnumerableSorter<TElement>? next)
             : base(comparer, descending, next)
         {
             _keySelector = keySelector;
@@ -809,7 +809,7 @@ namespace System.Linq
     {
         private readonly Func<TElement, ValueTask<TKey>> _keySelector;
 
-        public AsyncKeySelectorAsyncEnumerableSorter(Func<TElement, ValueTask<TKey>> keySelector, IComparer<TKey> comparer, bool descending, AsyncEnumerableSorter<TElement> next)
+        public AsyncKeySelectorAsyncEnumerableSorter(Func<TElement, ValueTask<TKey>> keySelector, IComparer<TKey> comparer, bool descending, AsyncEnumerableSorter<TElement>? next)
             : base(comparer, descending, next)
         {
             _keySelector = keySelector;
@@ -837,7 +837,7 @@ namespace System.Linq
         private readonly Func<TElement, CancellationToken, ValueTask<TKey>> _keySelector;
         private readonly CancellationToken _cancellationToken;
 
-        public AsyncKeySelectorAsyncEnumerableSorterWithCancellation(Func<TElement, CancellationToken, ValueTask<TKey>> keySelector, IComparer<TKey> comparer, bool descending, AsyncEnumerableSorter<TElement> next, CancellationToken cancellationToken)
+        public AsyncKeySelectorAsyncEnumerableSorterWithCancellation(Func<TElement, CancellationToken, ValueTask<TKey>> keySelector, IComparer<TKey> comparer, bool descending, AsyncEnumerableSorter<TElement>? next, CancellationToken cancellationToken)
             : base(comparer, descending, next)
         {
             _keySelector = keySelector;
@@ -927,8 +927,8 @@ namespace System.Linq
 
         // REVIEW: Consider to tear off an iterator object rather than storing this state here?
 
-        private TElement[] _buffer;
-        private int[] _indexes;
+        private TElement[]? _buffer;
+        private int[]? _indexes;
         private int _minIndexIterator;
         private int _maxIndexIterator;
 
@@ -978,7 +978,7 @@ namespace System.Linq
                 case AsyncIteratorState.Iterating:
                     if (_minIndexIterator <= _maxIndexIterator)
                     {
-                        _current = _buffer[_indexes[_minIndexIterator++]];
+                        _current = _buffer![_indexes![_minIndexIterator++]];
                         return true;
                     }
 
@@ -1017,6 +1017,7 @@ namespace System.Linq
             _keySelector = keySelector;
             _comparer = comparer;
             _descending = descending;
+            _lastKey = default!;
         }
 
         internal override ValueTask<int> Compare(TElement element, bool cacheLower, CancellationToken cancellationToken)
@@ -1092,6 +1093,7 @@ namespace System.Linq
             _keySelector = keySelector;
             _comparer = comparer;
             _descending = descending;
+            _lastKey = default!;
         }
 
         internal override async ValueTask<int> Compare(TElement element, bool cacheLower, CancellationToken cancellationToken)
@@ -1166,6 +1168,7 @@ namespace System.Linq
             _keySelector = keySelector;
             _comparer = comparer;
             _descending = descending;
+            _lastKey = default!;
         }
 
         internal override async ValueTask<int> Compare(TElement element, bool cacheLower, CancellationToken cancellationToken)

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

@@ -25,7 +25,7 @@ namespace System.Linq
             private readonly IAsyncEnumerable<TSource> _source;
 
             private int _index;
-            private TSource[] _items;
+            private TSource[]? _items;
 
             public ReverseAsyncIterator(IAsyncEnumerable<TSource> source)
             {
@@ -101,7 +101,7 @@ namespace System.Linq
                     case AsyncIteratorState.Iterating:
                         if (_index != -1)
                         {
-                            _current = _items[_index];
+                            _current = _items![_index];
                             --_index;
                             return true;
                         }

+ 12 - 12
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Select.cs

@@ -149,7 +149,7 @@ namespace System.Linq
             private readonly Func<TSource, TResult> _selector;
             private readonly IAsyncEnumerable<TSource> _source;
 
-            private IAsyncEnumerator<TSource> _enumerator;
+            private IAsyncEnumerator<TSource>? _enumerator;
 
             public SelectEnumerableAsyncIterator(IAsyncEnumerable<TSource> source, Func<TSource, TResult> selector)
             {
@@ -191,7 +191,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
+                        if (await _enumerator!.MoveNextAsync().ConfigureAwait(false))
                         {
                             _current = _selector(_enumerator.Current);
                             return true;
@@ -209,7 +209,7 @@ namespace System.Linq
         {
             private readonly Func<TSource, TResult> _selector;
             private readonly IList<TSource> _source;
-            private IEnumerator<TSource> _enumerator;
+            private IEnumerator<TSource>? _enumerator;
 
             public SelectIListIterator(IList<TSource> source, Func<TSource, TResult> selector)
             {
@@ -307,7 +307,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        if (_enumerator.MoveNext())
+                        if (_enumerator!.MoveNext())
                         {
                             _current = _selector(_enumerator.Current);
                             return true;
@@ -326,7 +326,7 @@ namespace System.Linq
             private readonly Func<TSource, ValueTask<TResult>> _selector;
             private readonly IAsyncEnumerable<TSource> _source;
 
-            private IAsyncEnumerator<TSource> _enumerator;
+            private IAsyncEnumerator<TSource>? _enumerator;
 
             public SelectEnumerableAsyncIteratorWithTask(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TResult>> selector)
             {
@@ -368,7 +368,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
+                        if (await _enumerator!.MoveNextAsync().ConfigureAwait(false))
                         {
                             _current = await _selector(_enumerator.Current).ConfigureAwait(false);
                             return true;
@@ -388,7 +388,7 @@ namespace System.Linq
             private readonly Func<TSource, CancellationToken, ValueTask<TResult>> _selector;
             private readonly IAsyncEnumerable<TSource> _source;
 
-            private IAsyncEnumerator<TSource> _enumerator;
+            private IAsyncEnumerator<TSource>? _enumerator;
 
             public SelectEnumerableAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TResult>> selector)
             {
@@ -430,7 +430,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
+                        if (await _enumerator!.MoveNextAsync().ConfigureAwait(false))
                         {
                             _current = await _selector(_enumerator.Current, _cancellationToken).ConfigureAwait(false);
                             return true;
@@ -454,7 +454,7 @@ namespace System.Linq
         {
             private readonly Func<TSource, ValueTask<TResult>> _selector;
             private readonly IList<TSource> _source;
-            private IEnumerator<TSource> _enumerator;
+            private IEnumerator<TSource>? _enumerator;
 
             public SelectIListIteratorWithTask(IList<TSource> source, Func<TSource, ValueTask<TResult>> selector)
             {
@@ -557,7 +557,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        if (_enumerator.MoveNext())
+                        if (_enumerator!.MoveNext())
                         {
                             _current = await _selector(_enumerator.Current).ConfigureAwait(false);
                             return true;
@@ -576,7 +576,7 @@ namespace System.Linq
         {
             private readonly Func<TSource, CancellationToken, ValueTask<TResult>> _selector;
             private readonly IList<TSource> _source;
-            private IEnumerator<TSource> _enumerator;
+            private IEnumerator<TSource>? _enumerator;
 
             public SelectIListIteratorWithTaskAndCancellation(IList<TSource> source, Func<TSource, CancellationToken, ValueTask<TResult>> selector)
             {
@@ -679,7 +679,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        if (_enumerator.MoveNext())
+                        if (_enumerator!.MoveNext())
                         {
                             _current = await _selector(_enumerator.Current, _cancellationToken).ConfigureAwait(false);
                             return true;

+ 12 - 12
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SelectMany.cs

@@ -321,8 +321,8 @@ namespace System.Linq
             private readonly IAsyncEnumerable<TSource> _source;
 
             private int _mode;
-            private IAsyncEnumerator<TResult> _resultEnumerator;
-            private IAsyncEnumerator<TSource> _sourceEnumerator;
+            private IAsyncEnumerator<TResult>? _resultEnumerator;
+            private IAsyncEnumerator<TSource>? _sourceEnumerator;
 
             public SelectManyAsyncIterator(IAsyncEnumerable<TSource> source, Func<TSource, IAsyncEnumerable<TResult>> selector)
             {
@@ -417,7 +417,7 @@ namespace System.Linq
                         switch (_mode)
                         {
                             case State_Source:
-                                if (await _sourceEnumerator.MoveNextAsync().ConfigureAwait(false))
+                                if (await _sourceEnumerator!.MoveNextAsync().ConfigureAwait(false))
                                 {
                                     if (_resultEnumerator != null)
                                     {
@@ -433,7 +433,7 @@ namespace System.Linq
                                 break;
 
                             case State_Result:
-                                if (await _resultEnumerator.MoveNextAsync().ConfigureAwait(false))
+                                if (await _resultEnumerator!.MoveNextAsync().ConfigureAwait(false))
                                 {
                                     _current = _resultEnumerator.Current;
                                     return true;
@@ -460,8 +460,8 @@ namespace System.Linq
             private readonly IAsyncEnumerable<TSource> _source;
 
             private int _mode;
-            private IAsyncEnumerator<TResult> _resultEnumerator;
-            private IAsyncEnumerator<TSource> _sourceEnumerator;
+            private IAsyncEnumerator<TResult>? _resultEnumerator;
+            private IAsyncEnumerator<TSource>? _sourceEnumerator;
 
             public SelectManyAsyncIteratorWithTask(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<IAsyncEnumerable<TResult>>> selector)
             {
@@ -558,7 +558,7 @@ namespace System.Linq
                         switch (_mode)
                         {
                             case State_Source:
-                                if (await _sourceEnumerator.MoveNextAsync().ConfigureAwait(false))
+                                if (await _sourceEnumerator!.MoveNextAsync().ConfigureAwait(false))
                                 {
                                     if (_resultEnumerator != null)
                                     {
@@ -574,7 +574,7 @@ namespace System.Linq
                                 break;
 
                             case State_Result:
-                                if (await _resultEnumerator.MoveNextAsync().ConfigureAwait(false))
+                                if (await _resultEnumerator!.MoveNextAsync().ConfigureAwait(false))
                                 {
                                     _current = _resultEnumerator.Current;
                                     return true;
@@ -602,8 +602,8 @@ namespace System.Linq
             private readonly IAsyncEnumerable<TSource> _source;
 
             private int _mode;
-            private IAsyncEnumerator<TResult> _resultEnumerator;
-            private IAsyncEnumerator<TSource> _sourceEnumerator;
+            private IAsyncEnumerator<TResult>? _resultEnumerator;
+            private IAsyncEnumerator<TSource>? _sourceEnumerator;
 
             public SelectManyAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<IAsyncEnumerable<TResult>>> selector)
             {
@@ -700,7 +700,7 @@ namespace System.Linq
                         switch (_mode)
                         {
                             case State_Source:
-                                if (await _sourceEnumerator.MoveNextAsync().ConfigureAwait(false))
+                                if (await _sourceEnumerator!.MoveNextAsync().ConfigureAwait(false))
                                 {
                                     if (_resultEnumerator != null)
                                     {
@@ -716,7 +716,7 @@ namespace System.Linq
                                 break;
 
                             case State_Result:
-                                if (await _resultEnumerator.MoveNextAsync().ConfigureAwait(false))
+                                if (await _resultEnumerator!.MoveNextAsync().ConfigureAwait(false))
                                 {
                                     _current = _resultEnumerator.Current;
                                     return true;

+ 1 - 1
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SequenceEqual.cs

@@ -13,7 +13,7 @@ namespace System.Linq
         public static ValueTask<bool> SequenceEqualAsync<TSource>(this IAsyncEnumerable<TSource> first, IAsyncEnumerable<TSource> second, CancellationToken cancellationToken = default) =>
             SequenceEqualAsync(first, second, comparer: null, cancellationToken);
 
-        public static ValueTask<bool> SequenceEqualAsync<TSource>(this IAsyncEnumerable<TSource> first, IAsyncEnumerable<TSource> second, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<bool> SequenceEqualAsync<TSource>(this IAsyncEnumerable<TSource> first, IAsyncEnumerable<TSource> second, IEqualityComparer<TSource>? comparer, CancellationToken cancellationToken = default)
         {
             if (first == null)
                 throw Error.ArgumentNull(nameof(first));

+ 5 - 5
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SingleLinkedNode.cs

@@ -44,7 +44,7 @@ namespace System.Linq
         /// <summary>
         /// The next node in the singly-linked list.
         /// </summary>
-        public SingleLinkedNode<TSource> Linked { get; }
+        public SingleLinkedNode<TSource>? Linked { get; }
 
         /// <summary>
         /// Creates a new node that holds the specified item and is linked to this node.
@@ -58,7 +58,7 @@ namespace System.Linq
         public int GetCount()
         {
             var count = 0;
-            for (var node = this; node != null; node = node.Linked)
+            for (SingleLinkedNode<TSource>? node = this; node != null; node = node.Linked)
             {
                 count++;
             }
@@ -86,10 +86,10 @@ namespace System.Linq
         {
             Debug.Assert(index >= 0 && index < GetCount());
 
-            var node = this;
+            SingleLinkedNode<TSource>? node = this;
             for (; index > 0; index--)
             {
-                node = node.Linked;
+                node = node!.Linked;
             }
 
             Debug.Assert(node != null);
@@ -106,7 +106,7 @@ namespace System.Linq
 
             var array = new TSource[count];
             var index = count;
-            for (var node = this; node != null; node = node.Linked)
+            for (SingleLinkedNode<TSource>? node = this; node != null; node = node.Linked)
             {
                 --index;
                 array[index] = node.Item;

+ 9 - 9
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SingleOrDefault.cs

@@ -17,13 +17,13 @@ namespace System.Linq
 
             return Core(source, cancellationToken);
 
-            async ValueTask<TSource> Core(IAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
+            static async ValueTask<TSource> Core(IAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
             {
                 if (source is IList<TSource> list)
                 {
                     switch (list.Count)
                     {
-                        case 0: return default;
+                        case 0: return default!;
                         case 1: return list[0];
                     }
 
@@ -34,7 +34,7 @@ namespace System.Linq
                 {
                     if (!await e.MoveNextAsync())
                     {
-                        return default;
+                        return default!;
                     }
 
                     var result = e.Current;
@@ -58,7 +58,7 @@ namespace System.Linq
 
             return Core(source, predicate, cancellationToken);
 
-            async ValueTask<TSource> Core(IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate, CancellationToken cancellationToken)
+            static async ValueTask<TSource> Core(IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate, CancellationToken cancellationToken)
             {
                 await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
                 {
@@ -81,7 +81,7 @@ namespace System.Linq
                     }
                 }
 
-                return default;
+                return default!;
             }
         }
 
@@ -94,7 +94,7 @@ namespace System.Linq
 
             return Core(source, predicate, cancellationToken);
 
-            async ValueTask<TSource> Core(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<bool>> predicate, CancellationToken cancellationToken)
+            static async ValueTask<TSource> Core(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<bool>> predicate, CancellationToken cancellationToken)
             {
                 await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
                 {
@@ -117,7 +117,7 @@ namespace System.Linq
                     }
                 }
 
-                return default;
+                return default!;
             }
         }
 
@@ -131,7 +131,7 @@ namespace System.Linq
 
             return Core(source, predicate, cancellationToken);
 
-            async ValueTask<TSource> Core(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<bool>> predicate, CancellationToken cancellationToken)
+            static async ValueTask<TSource> Core(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<bool>> predicate, CancellationToken cancellationToken)
             {
                 await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
                 {
@@ -154,7 +154,7 @@ namespace System.Linq
                     }
                 }
 
-                return default;
+                return default!;
             }
         }
 #endif

+ 7 - 10
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToAsyncEnumerable.Observable.cs

@@ -23,11 +23,11 @@ namespace System.Linq
         {
             private readonly IObservable<TSource> _source;
 
-            private ConcurrentQueue<TSource> _values = new ConcurrentQueue<TSource>();
-            private Exception _error;
+            private ConcurrentQueue<TSource>? _values = new ConcurrentQueue<TSource>();
+            private Exception? _error;
             private bool _completed;
-            private TaskCompletionSource<bool> _signal;
-            private IDisposable _subscription;
+            private TaskCompletionSource<bool>? _signal;
+            private IDisposable? _subscription;
             private CancellationTokenRegistration _ctr;
 
             public ObservableAsyncEnumerable(IObservable<TSource> source) => _source = source;
@@ -78,7 +78,7 @@ namespace System.Linq
                         {
                             var completed = Volatile.Read(ref _completed);
 
-                            if (_values.TryDequeue(out _current))
+                            if (_values!.TryDequeue(out _current))
                             {
                                 return true;
                             }
@@ -166,7 +166,7 @@ namespace System.Linq
 
             private Task Resume()
             {
-                TaskCompletionSource<bool> newSignal = null;
+                TaskCompletionSource<bool>? newSignal = null;
 
                 while (true)
                 {
@@ -177,10 +177,7 @@ namespace System.Linq
                         return signal.Task;
                     }
 
-                    if (newSignal == null)
-                    {
-                        newSignal = new TaskCompletionSource<bool>();
-                    }
+                    newSignal ??= new TaskCompletionSource<bool>();
 
                     if (Interlocked.CompareExchange(ref _signal, newSignal, null) == null)
                     {

+ 6 - 6
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToAsyncEnumerable.cs

@@ -32,7 +32,7 @@ namespace System.Linq
         {
             private readonly IEnumerable<T> _source;
 
-            private IEnumerator<T> _enumerator;
+            private IEnumerator<T>? _enumerator;
  
             public AsyncEnumerableAdapter(IEnumerable<T> source)
             {
@@ -64,7 +64,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        if (_enumerator.MoveNext())
+                        if (_enumerator!.MoveNext())
                         {
                             _current = _enumerator.Current;
                             return true;
@@ -107,7 +107,7 @@ namespace System.Linq
         private sealed class AsyncIListEnumerableAdapter<T> : AsyncIterator<T>, IAsyncIListProvider<T>, IList<T>
         {
             private readonly IList<T> _source;
-            private IEnumerator<T> _enumerator;
+            private IEnumerator<T>? _enumerator;
 
             public AsyncIListEnumerableAdapter(IList<T> source)
             {
@@ -139,7 +139,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        if (_enumerator.MoveNext())
+                        if (_enumerator!.MoveNext())
                         {
                             _current = _enumerator.Current;
                             return true;
@@ -214,7 +214,7 @@ namespace System.Linq
         private sealed class AsyncICollectionEnumerableAdapter<T> : AsyncIterator<T>, IAsyncIListProvider<T>, ICollection<T>
         {
             private readonly ICollection<T> _source;
-            private IEnumerator<T> _enumerator;
+            private IEnumerator<T>? _enumerator;
 
             public AsyncICollectionEnumerableAdapter(ICollection<T> source)
             {
@@ -246,7 +246,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        if (_enumerator.MoveNext())
+                        if (_enumerator!.MoveNext())
                         {
                             _current = _enumerator.Current;
                             return true;

+ 12 - 12
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToDictionary.cs

@@ -13,7 +13,7 @@ namespace System.Linq
         public static ValueTask<Dictionary<TKey, TSource>> ToDictionaryAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, CancellationToken cancellationToken = default) =>
             ToDictionaryAsync(source, keySelector, comparer: null, cancellationToken);
 
-        public static ValueTask<Dictionary<TKey, TSource>> ToDictionaryAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<Dictionary<TKey, TSource>> ToDictionaryAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -22,7 +22,7 @@ namespace System.Linq
 
             return Core(source, keySelector, comparer, cancellationToken);
 
-            static async ValueTask<Dictionary<TKey, TSource>> Core(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
+            static async ValueTask<Dictionary<TKey, TSource>> Core(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken)
             {
                 var d = new Dictionary<TKey, TSource>(comparer);
 
@@ -40,7 +40,7 @@ namespace System.Linq
         internal static ValueTask<Dictionary<TKey, TSource>> ToDictionaryAwaitAsyncCore<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, CancellationToken cancellationToken = default) =>
             ToDictionaryAwaitAsyncCore<TSource, TKey>(source, keySelector, comparer: null, cancellationToken);
 
-        internal static ValueTask<Dictionary<TKey, TSource>> ToDictionaryAwaitAsyncCore<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        internal static ValueTask<Dictionary<TKey, TSource>> ToDictionaryAwaitAsyncCore<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -49,7 +49,7 @@ namespace System.Linq
 
             return Core(source, keySelector, comparer, cancellationToken);
 
-            static async ValueTask<Dictionary<TKey, TSource>> Core(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
+            static async ValueTask<Dictionary<TKey, TSource>> Core(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken)
             {
                 var d = new Dictionary<TKey, TSource>(comparer);
 
@@ -68,7 +68,7 @@ namespace System.Linq
         internal static ValueTask<Dictionary<TKey, TSource>> ToDictionaryAwaitWithCancellationAsyncCore<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, CancellationToken cancellationToken = default) =>
             ToDictionaryAwaitWithCancellationAsyncCore(source, keySelector, comparer: null, cancellationToken);
 
-        internal static ValueTask<Dictionary<TKey, TSource>> ToDictionaryAwaitWithCancellationAsyncCore<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        internal static ValueTask<Dictionary<TKey, TSource>> ToDictionaryAwaitWithCancellationAsyncCore<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -77,7 +77,7 @@ namespace System.Linq
 
             return Core(source, keySelector, comparer, cancellationToken);
 
-            static async ValueTask<Dictionary<TKey, TSource>> Core(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
+            static async ValueTask<Dictionary<TKey, TSource>> Core(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken)
             {
                 var d = new Dictionary<TKey, TSource>(comparer);
 
@@ -96,7 +96,7 @@ namespace System.Linq
         public static ValueTask<Dictionary<TKey, TElement>> ToDictionaryAsync<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, CancellationToken cancellationToken = default) =>
             ToDictionaryAsync(source, keySelector, elementSelector, comparer: null, cancellationToken);
 
-        public static ValueTask<Dictionary<TKey, TElement>> ToDictionaryAsync<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<Dictionary<TKey, TElement>> ToDictionaryAsync<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -107,7 +107,7 @@ namespace System.Linq
 
             return Core(source, keySelector, elementSelector, comparer, cancellationToken);
 
-            static async ValueTask<Dictionary<TKey, TElement>> Core(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
+            static async ValueTask<Dictionary<TKey, TElement>> Core(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken)
             {
                 var d = new Dictionary<TKey, TElement>(comparer);
 
@@ -126,7 +126,7 @@ namespace System.Linq
         internal static ValueTask<Dictionary<TKey, TElement>> ToDictionaryAwaitAsyncCore<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, CancellationToken cancellationToken = default) =>
             ToDictionaryAwaitAsyncCore<TSource, TKey, TElement>(source, keySelector, elementSelector, comparer: null, cancellationToken);
 
-        internal static ValueTask<Dictionary<TKey, TElement>> ToDictionaryAwaitAsyncCore<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        internal static ValueTask<Dictionary<TKey, TElement>> ToDictionaryAwaitAsyncCore<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -137,7 +137,7 @@ namespace System.Linq
 
             return Core(source, keySelector, elementSelector, comparer, cancellationToken);
 
-            static async ValueTask<Dictionary<TKey, TElement>> Core(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
+            static async ValueTask<Dictionary<TKey, TElement>> Core(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken)
             {
                 var d = new Dictionary<TKey, TElement>(comparer);
 
@@ -157,7 +157,7 @@ namespace System.Linq
         internal static ValueTask<Dictionary<TKey, TElement>> ToDictionaryAwaitWithCancellationAsyncCore<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TSource, CancellationToken, ValueTask<TElement>> elementSelector, CancellationToken cancellationToken = default) =>
             ToDictionaryAwaitWithCancellationAsyncCore(source, keySelector, elementSelector, comparer: null, cancellationToken);
 
-        internal static ValueTask<Dictionary<TKey, TElement>> ToDictionaryAwaitWithCancellationAsyncCore<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TSource, CancellationToken, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        internal static ValueTask<Dictionary<TKey, TElement>> ToDictionaryAwaitWithCancellationAsyncCore<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TSource, CancellationToken, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -168,7 +168,7 @@ namespace System.Linq
 
             return Core(source, keySelector, elementSelector, comparer, cancellationToken);
 
-            static async ValueTask<Dictionary<TKey, TElement>> Core(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TSource, CancellationToken, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
+            static async ValueTask<Dictionary<TKey, TElement>> Core(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TSource, CancellationToken, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken)
             {
                 var d = new Dictionary<TKey, TElement>(comparer);
 

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

@@ -19,9 +19,9 @@ namespace System.Linq
 
             return Core(source);
 
-            IEnumerable<TSource> Core(IAsyncEnumerable<TSource> _source)
+            static IEnumerable<TSource> Core(IAsyncEnumerable<TSource> source)
             {
-                var e = _source.GetAsyncEnumerator(default);
+                var e = source.GetAsyncEnumerator(default);
 
                 try
                 {

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

@@ -13,14 +13,14 @@ namespace System.Linq
         public static ValueTask<HashSet<TSource>> ToHashSetAsync<TSource>(this IAsyncEnumerable<TSource> source, CancellationToken cancellationToken = default) =>
             ToHashSetAsync(source, comparer: null, cancellationToken);
 
-        public static ValueTask<HashSet<TSource>> ToHashSetAsync<TSource>(this IAsyncEnumerable<TSource> source, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<HashSet<TSource>> ToHashSetAsync<TSource>(this IAsyncEnumerable<TSource> source, IEqualityComparer<TSource>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
 
             return Core(source, comparer, cancellationToken);
 
-            static async ValueTask<HashSet<TSource>> Core(IAsyncEnumerable<TSource> source, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken)
+            static async ValueTask<HashSet<TSource>> Core(IAsyncEnumerable<TSource> source, IEqualityComparer<TSource>? comparer, CancellationToken cancellationToken)
             {
                 var set = new HashSet<TSource>(comparer);
 

+ 12 - 12
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToLookup.cs

@@ -13,7 +13,7 @@ namespace System.Linq
         public static ValueTask<ILookup<TKey, TSource>> ToLookupAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, CancellationToken cancellationToken = default) =>
             ToLookupAsync(source, keySelector, comparer: null, cancellationToken);
 
-        public static ValueTask<ILookup<TKey, TSource>> ToLookupAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<ILookup<TKey, TSource>> ToLookupAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -22,7 +22,7 @@ namespace System.Linq
 
             return Core(source, keySelector, comparer, cancellationToken);
 
-            static async ValueTask<ILookup<TKey, TSource>> Core(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
+            static async ValueTask<ILookup<TKey, TSource>> Core(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken)
             {
                 return await Internal.Lookup<TKey, TSource>.CreateAsync(source, keySelector, comparer, cancellationToken).ConfigureAwait(false);
             }
@@ -31,7 +31,7 @@ namespace System.Linq
         internal static ValueTask<ILookup<TKey, TSource>> ToLookupAwaitAsyncCore<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, CancellationToken cancellationToken = default) =>
             ToLookupAwaitAsyncCore<TSource, TKey>(source, keySelector, comparer:null, cancellationToken);
 
-        internal static ValueTask<ILookup<TKey, TSource>> ToLookupAwaitAsyncCore<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        internal static ValueTask<ILookup<TKey, TSource>> ToLookupAwaitAsyncCore<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -40,7 +40,7 @@ namespace System.Linq
 
             return Core(source, keySelector, comparer, cancellationToken);
 
-            async ValueTask<ILookup<TKey, TSource>> Core(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
+            static async ValueTask<ILookup<TKey, TSource>> Core(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken)
             {
                 return await Internal.LookupWithTask<TKey, TSource>.CreateAsync(source, keySelector, comparer, cancellationToken).ConfigureAwait(false);
             }
@@ -50,7 +50,7 @@ namespace System.Linq
         internal static ValueTask<ILookup<TKey, TSource>> ToLookupAwaitWithCancellationAsyncCore<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, CancellationToken cancellationToken = default) =>
             ToLookupAwaitWithCancellationAsyncCore(source, keySelector, comparer: null, cancellationToken);
 
-        internal static ValueTask<ILookup<TKey, TSource>> ToLookupAwaitWithCancellationAsyncCore<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        internal static ValueTask<ILookup<TKey, TSource>> ToLookupAwaitWithCancellationAsyncCore<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -59,7 +59,7 @@ namespace System.Linq
 
             return Core(source, keySelector, comparer, cancellationToken);
 
-            static async ValueTask<ILookup<TKey, TSource>> Core(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
+            static async ValueTask<ILookup<TKey, TSource>> Core(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken)
             {
                 return await Internal.LookupWithTask<TKey, TSource>.CreateAsync(source, keySelector, comparer, cancellationToken).ConfigureAwait(false);
             }
@@ -69,7 +69,7 @@ namespace System.Linq
         public static ValueTask<ILookup<TKey, TElement>> ToLookupAsync<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, CancellationToken cancellationToken = default) =>
             ToLookupAsync(source, keySelector, elementSelector, comparer: null, cancellationToken);
 
-        public static ValueTask<ILookup<TKey, TElement>> ToLookupAsync<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        public static ValueTask<ILookup<TKey, TElement>> ToLookupAsync<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -80,7 +80,7 @@ namespace System.Linq
 
             return Core(source, keySelector, elementSelector, comparer, cancellationToken);
 
-            static async ValueTask<ILookup<TKey, TElement>> Core(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
+            static async ValueTask<ILookup<TKey, TElement>> Core(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken)
             {
                 return await Internal.Lookup<TKey, TElement>.CreateAsync(source, keySelector, elementSelector, comparer, cancellationToken).ConfigureAwait(false);
             }
@@ -89,7 +89,7 @@ namespace System.Linq
         internal static ValueTask<ILookup<TKey, TElement>> ToLookupAwaitAsyncCore<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, CancellationToken cancellationToken = default) =>
             ToLookupAwaitAsyncCore<TSource, TKey, TElement>(source, keySelector, elementSelector, comparer: null, cancellationToken);
 
-        internal static ValueTask<ILookup<TKey, TElement>> ToLookupAwaitAsyncCore<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        internal static ValueTask<ILookup<TKey, TElement>> ToLookupAwaitAsyncCore<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -100,7 +100,7 @@ namespace System.Linq
 
             return Core(source, keySelector, elementSelector, comparer, cancellationToken);
 
-            static async ValueTask<ILookup<TKey, TElement>> Core(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
+            static async ValueTask<ILookup<TKey, TElement>> Core(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken)
             {
                 return await Internal.LookupWithTask<TKey, TElement>.CreateAsync(source, keySelector, elementSelector, comparer, cancellationToken).ConfigureAwait(false);
             }
@@ -110,7 +110,7 @@ namespace System.Linq
         internal static ValueTask<ILookup<TKey, TElement>> ToLookupAwaitWithCancellationAsyncCore<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TSource, CancellationToken, ValueTask<TElement>> elementSelector, CancellationToken cancellationToken = default) =>
             ToLookupAwaitWithCancellationAsyncCore(source, keySelector, elementSelector, comparer: null, cancellationToken);
 
-        internal static ValueTask<ILookup<TKey, TElement>> ToLookupAwaitWithCancellationAsyncCore<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TSource, CancellationToken, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
+        internal static ValueTask<ILookup<TKey, TElement>> ToLookupAwaitWithCancellationAsyncCore<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TSource, CancellationToken, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -121,7 +121,7 @@ namespace System.Linq
 
             return Core(source, keySelector, elementSelector, comparer, cancellationToken);
 
-            static async ValueTask<ILookup<TKey, TElement>> Core(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TSource, CancellationToken, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
+            static async ValueTask<ILookup<TKey, TElement>> Core(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, Func<TSource, CancellationToken, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken)
             {
                 return await Internal.LookupWithTask<TKey, TElement>.CreateAsync(source, keySelector, elementSelector, comparer, cancellationToken).ConfigureAwait(false);
             }

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

@@ -14,7 +14,7 @@ namespace System.Linq
         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)
+        public static IAsyncEnumerable<TSource> Union<TSource>(this IAsyncEnumerable<TSource> first, IAsyncEnumerable<TSource> second, IEqualityComparer<TSource>? comparer)
         {
             if (first == null)
                 throw Error.ArgumentNull(nameof(first));
@@ -24,7 +24,7 @@ namespace System.Linq
             return first is UnionAsyncIterator<TSource> union && AreEqualityComparersEqual(comparer, union._comparer) ? union.Union(second) : new UnionAsyncIterator2<TSource>(first, second, comparer);
         }
 
-        private static bool AreEqualityComparersEqual<TSource>(IEqualityComparer<TSource> first, IEqualityComparer<TSource> second)
+        private static bool AreEqualityComparersEqual<TSource>(IEqualityComparer<TSource>? first, IEqualityComparer<TSource>? second)
         {
             return first == second || (first != null && second != null && first.Equals(second));
         }
@@ -35,12 +35,12 @@ namespace System.Linq
         /// <typeparam name="TSource">The type of the source enumerables.</typeparam>
         private abstract class UnionAsyncIterator<TSource> : AsyncIterator<TSource>, IAsyncIListProvider<TSource>
         {
-            internal readonly IEqualityComparer<TSource> _comparer;
-            private IAsyncEnumerator<TSource> _enumerator;
-            private Set<TSource> _set;
+            internal readonly IEqualityComparer<TSource>? _comparer;
+            private IAsyncEnumerator<TSource>? _enumerator;
+            private Set<TSource>? _set;
             private int _index;
 
-            protected UnionAsyncIterator(IEqualityComparer<TSource> comparer)
+            protected UnionAsyncIterator(IEqualityComparer<TSource>? comparer)
             {
                 _comparer = comparer;
             }
@@ -57,7 +57,7 @@ namespace System.Linq
                 await base.DisposeAsync().ConfigureAwait(false);
             }
 
-            internal abstract IAsyncEnumerable<TSource> GetEnumerable(int index);
+            internal abstract IAsyncEnumerable<TSource>? GetEnumerable(int index);
 
             internal abstract UnionAsyncIterator<TSource> Union(IAsyncEnumerable<TSource> next);
 
@@ -74,7 +74,7 @@ namespace System.Linq
             private void StoreFirst()
             {
                 var set = new Set<TSource>(_comparer);
-                var element = _enumerator.Current;
+                var element = _enumerator!.Current;
                 set.Add(element);
                 _current = element;
                 _set = set;
@@ -85,7 +85,7 @@ namespace System.Linq
                 var set = _set;
                 Debug.Assert(set != null);
 
-                while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
+                while (await _enumerator!.MoveNextAsync().ConfigureAwait(false))
                 {
                     var element = _enumerator.Current;
                     if (set.Add(element))
@@ -207,7 +207,7 @@ namespace System.Linq
             private readonly IAsyncEnumerable<TSource> _first;
             private readonly IAsyncEnumerable<TSource> _second;
 
-            public UnionAsyncIterator2(IAsyncEnumerable<TSource> first, IAsyncEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
+            public UnionAsyncIterator2(IAsyncEnumerable<TSource> first, IAsyncEnumerable<TSource> second, IEqualityComparer<TSource>? comparer)
                 : base(comparer)
             {
                 Debug.Assert(first != null);
@@ -218,7 +218,7 @@ namespace System.Linq
 
             public override AsyncIteratorBase<TSource> Clone() => new UnionAsyncIterator2<TSource>(_first, _second, _comparer);
 
-            internal override IAsyncEnumerable<TSource> GetEnumerable(int index)
+            internal override IAsyncEnumerable<TSource>? GetEnumerable(int index)
             {
                 Debug.Assert(index >= 0 && index <= 2);
                 switch (index)
@@ -248,11 +248,11 @@ namespace System.Linq
             private readonly SingleLinkedNode<IAsyncEnumerable<TSource>> _sources;
             private readonly int _headIndex;
 
-            public UnionAsyncIteratorN(SingleLinkedNode<IAsyncEnumerable<TSource>> sources, int headIndex, IEqualityComparer<TSource> comparer)
+            public UnionAsyncIteratorN(SingleLinkedNode<IAsyncEnumerable<TSource>> sources, int headIndex, IEqualityComparer<TSource>? comparer)
                 : base(comparer)
             {
                 Debug.Assert(headIndex >= 2);
-                Debug.Assert(sources?.GetCount() == headIndex + 1);
+                Debug.Assert(sources.GetCount() == headIndex + 1);
 
                 _sources = sources;
                 _headIndex = headIndex;
@@ -260,7 +260,7 @@ namespace System.Linq
 
             public override AsyncIteratorBase<TSource> Clone() => new UnionAsyncIteratorN<TSource>(_sources, _headIndex, _comparer);
 
-            internal override IAsyncEnumerable<TSource> GetEnumerable(int index) => index > _headIndex ? null : _sources.GetNode(_headIndex - index).Item;
+            internal override IAsyncEnumerable<TSource>? GetEnumerable(int index) => index > _headIndex ? null : _sources.GetNode(_headIndex - index).Item;
 
             internal override UnionAsyncIterator<TSource> Union(IAsyncEnumerable<TSource> next)
             {

+ 8 - 8
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Where.cs

@@ -151,7 +151,7 @@ namespace System.Linq
         {
             private readonly Func<TSource, bool> _predicate;
             private readonly IAsyncEnumerable<TSource> _source;
-            private IAsyncEnumerator<TSource> _enumerator;
+            private IAsyncEnumerator<TSource>? _enumerator;
 
             public WhereEnumerableAsyncIterator(IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate)
             {
@@ -198,7 +198,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
+                        while (await _enumerator!.MoveNextAsync().ConfigureAwait(false))
                         {
                             var item = _enumerator.Current;
                             if (_predicate(item))
@@ -220,7 +220,7 @@ namespace System.Linq
         {
             private readonly Func<TSource, ValueTask<bool>> _predicate;
             private readonly IAsyncEnumerable<TSource> _source;
-            private IAsyncEnumerator<TSource> _enumerator;
+            private IAsyncEnumerator<TSource>? _enumerator;
 
             public WhereEnumerableAsyncIteratorWithTask(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<bool>> predicate)
             {
@@ -262,7 +262,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
+                        while (await _enumerator!.MoveNextAsync().ConfigureAwait(false))
                         {
                             var item = _enumerator.Current;
                             if (await _predicate(item).ConfigureAwait(false))
@@ -285,7 +285,7 @@ namespace System.Linq
         {
             private readonly Func<TSource, CancellationToken, ValueTask<bool>> _predicate;
             private readonly IAsyncEnumerable<TSource> _source;
-            private IAsyncEnumerator<TSource> _enumerator;
+            private IAsyncEnumerator<TSource>? _enumerator;
 
             public WhereEnumerableAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<bool>> predicate)
             {
@@ -327,7 +327,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
+                        while (await _enumerator!.MoveNextAsync().ConfigureAwait(false))
                         {
                             var item = _enumerator.Current;
                             if (await _predicate(item, _cancellationToken).ConfigureAwait(false))
@@ -352,7 +352,7 @@ namespace System.Linq
             private readonly Func<TSource, TResult> _selector;
             private readonly IAsyncEnumerable<TSource> _source;
 
-            private IAsyncEnumerator<TSource> _enumerator;
+            private IAsyncEnumerator<TSource>? _enumerator;
 
             public WhereSelectEnumerableAsyncIterator(IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate, Func<TSource, TResult> selector)
             {
@@ -396,7 +396,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
+                        while (await _enumerator!.MoveNextAsync().ConfigureAwait(false))
                         {
                             var item = _enumerator.Current;
                             if (_predicate(item))

+ 2 - 2
Ix.NET/Source/System.Linq.Async/System/Linq/Set.cs

@@ -20,7 +20,7 @@ namespace System.Linq
 #endif
         private Slot[] _slots;
 
-        public Set(IEqualityComparer<TElement> comparer)
+        public Set(IEqualityComparer<TElement>? comparer)
         {
             _comparer = comparer ?? EqualityComparer<TElement>.Default;
             _buckets = new int[7];
@@ -82,7 +82,7 @@ namespace System.Linq
                     }
 
                     _slots[i]._hashCode = -1;
-                    _slots[i]._value = default;
+                    _slots[i]._value = default!;
                     _slots[i]._next = -1;
                     return true;
                 }