Browse Source

Code-gen for Average.

Bart De Smet 7 years ago
parent
commit
dc2706c7ad

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

@@ -4,6 +4,19 @@
     <TargetFrameworks>net45;net46;netstandard1.4;netstandard2.0</TargetFrameworks>
   </PropertyGroup>
 
+  <ItemGroup>
+    <None Include="System\Linq\Operators\Select.Opt.Generated.cs">
+      <DesignTime>True</DesignTime>
+      <AutoGen>True</AutoGen>
+      <DependentUpon>Select.Opt.Generated.tt</DependentUpon>
+    </None>
+    <None Include="System\Linq\Operators\Where.Opt.Generated.cs">
+      <DesignTime>True</DesignTime>
+      <AutoGen>True</AutoGen>
+      <DependentUpon>Where.Opt.Generated.tt</DependentUpon>
+    </None>
+  </ItemGroup>
+
   <ItemGroup>
     <PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.1" />
   </ItemGroup>
@@ -19,11 +32,21 @@
       <DesignTime>True</DesignTime>
       <AutoGen>True</AutoGen>
     </Compile>
+    <Compile Update="System\Linq\Operators\Select.Opt.Generated.cs">
+      <DesignTime>True</DesignTime>
+      <AutoGen>True</AutoGen>
+      <DependentUpon>Select.Opt.Generated.tt</DependentUpon>
+    </Compile>
     <Compile Update="System\Linq\Operators\Sum.Generated.cs">
       <DependentUpon>Sum.Generated.tt</DependentUpon>
       <DesignTime>True</DesignTime>
       <AutoGen>True</AutoGen>
     </Compile>
+    <Compile Update="System\Linq\Operators\Where.Opt.Generated.cs">
+      <DesignTime>True</DesignTime>
+      <AutoGen>True</AutoGen>
+      <DependentUpon>Where.Opt.Generated.tt</DependentUpon>
+    </Compile>
   </ItemGroup>
 
   <ItemGroup>
@@ -35,10 +58,18 @@
       <LastGenOutput>MinMax.Generated.cs</LastGenOutput>
       <Generator>TextTemplatingFileGenerator</Generator>
     </None>
+    <None Update="System\Linq\Operators\Select.Opt.Generated.tt">
+      <Generator>TextTemplatingFileGenerator</Generator>
+      <LastGenOutput>Select.Opt.Generated.cs</LastGenOutput>
+    </None>
     <None Update="System\Linq\Operators\Sum.Generated.tt">
       <LastGenOutput>Sum.Generated.cs</LastGenOutput>
       <Generator>TextTemplatingFileGenerator</Generator>
     </None>
+    <None Update="System\Linq\Operators\Where.Opt.Generated.tt">
+      <Generator>TextTemplatingFileGenerator</Generator>
+      <LastGenOutput>Where.Opt.Generated.cs</LastGenOutput>
+    </None>
   </ItemGroup>
 
   <ItemGroup>

File diff suppressed because it is too large
+ 816 - 26
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Average.Generated.cs


+ 330 - 16
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Average.Generated.tt

@@ -6,7 +6,7 @@
 <#@ output extension=".cs" #>
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the Apache 2.0 License.
-// See the LICENSE file in the project root for more information. 
+// See the LICENSE file in the project root for more information.
 
 using System.Collections.Generic;
 using System.Threading;
@@ -19,28 +19,114 @@ namespace System.Linq
 <#
 var os = new[]
 {
-    new { type = "int", res = "double" },
-    new { type = "long", res = "double" },
-    new { type = "float", res = "float" },
-    new { type = "double", res = "double" },
-    new { type = "decimal", res = "decimal" },
-    new { type = "int?", res = "double?" },
-    new { type = "long?", res = "double?" },
-    new { type = "float?", res = "float?" },
-    new { type = "double?", res = "double?" },
-    new { type = "decimal?", res = "decimal?" },
+    new { type = "int", res = "double", sum = "long" },
+    new { type = "long", res = "double", sum = "long" },
+    new { type = "float", res = "float", sum = "double" },
+    new { type = "double", res = "double", sum = "double" },
+    new { type = "decimal", res = "decimal", sum = "decimal" },
+    new { type = "int?", res = "double?", sum = "long" },
+    new { type = "long?", res = "double?", sum = "long" },
+    new { type = "float?", res = "float?", sum = "double" },
+    new { type = "double?", res = "double?", sum = "double" },
+    new { type = "decimal?", res = "decimal?", sum = "decimal" },
 };
 
 foreach (var o in os)
 {
-    var n = o.type.EndsWith("?") ? ".GetValueOrDefault()" : "";
+    var isNullable = o.type.EndsWith("?");
+    var t = o.type.TrimEnd('?');
+
+    string res = "";
+
+    if (t == "int" || t == "long")
+        res = "(double)sum / count";
+    else if (t == "double" || t == "decimal")
+        res = "sum / count";
+    else if (t == "float")
+        res = "(float)(sum / count)";
 #>
         public static Task<<#=o.res#>> AverageAsync(this IAsyncEnumerable<<#=o.type#>> source, CancellationToken cancellationToken = default)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
 
-            return AverageCore(source, cancellationToken);
+            return Core(source, cancellationToken);
+
+            async Task<<#=o.res#>> Core(IAsyncEnumerable<<#=o.type#>> _source, CancellationToken _cancellationToken)
+            {
+<#
+if (isNullable)
+{
+#>
+                var e = _source.GetAsyncEnumerator(_cancellationToken);
+
+                try
+                {
+                    while (await e.MoveNextAsync().ConfigureAwait(false))
+                    {
+                        var v = e.Current;
+                        if (v.HasValue)
+                        {
+                            <#=o.sum#> sum = v.GetValueOrDefault();
+                            long count = 1;
+                            checked
+                            {
+                                while (await e.MoveNextAsync().ConfigureAwait(false))
+                                {
+                                    v = e.Current;
+                                    if (v.HasValue)
+                                    {
+                                        sum += v.GetValueOrDefault();
+                                        ++count;
+                                    }
+                                }
+                            }
+
+                            return <#=res#>;
+                        }
+                    }
+                }
+                finally
+                {
+                    await e.DisposeAsync().ConfigureAwait(false);
+                }
+
+                return null;
+<#
+}
+else
+{
+#>
+                var e = _source.GetAsyncEnumerator(_cancellationToken);
+
+                try
+                {
+                    if (!await e.MoveNextAsync().ConfigureAwait(false))
+                    {
+                        throw Error.NoElements();
+                    }
+
+                    <#=o.sum#> sum = e.Current;
+                    long count = 1;
+                    checked
+                    {
+                        while (await e.MoveNextAsync().ConfigureAwait(false))
+                        {
+                            sum += e.Current;
+                            ++count;
+                        }
+                    }
+
+                    return <#=res#>;
+                }
+                finally
+                {
+                    await e.DisposeAsync().ConfigureAwait(false);
+                }
+<#
+}
+#>
+            }
         }
 
         public static Task<<#=o.res#>> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, <#=o.type#>> selector, CancellationToken cancellationToken = default)
@@ -50,7 +136,83 @@ foreach (var o in os)
             if (selector == null)
                 throw Error.ArgumentNull(nameof(selector));
 
-            return AverageCore(source, selector, cancellationToken);
+            return Core(source, selector, cancellationToken);
+
+            async Task<<#=o.res#>> Core(IAsyncEnumerable<TSource> _source, Func<TSource, <#=o.type#>> _selector, CancellationToken _cancellationToken)
+            {
+<#
+if (isNullable)
+{
+#>
+                var e = _source.GetAsyncEnumerator(_cancellationToken);
+
+                try
+                {
+                    while (await e.MoveNextAsync().ConfigureAwait(false))
+                    {
+                        var v = _selector(e.Current);
+                        if (v.HasValue)
+                        {
+                            <#=o.sum#> sum = v.GetValueOrDefault();
+                            long count = 1;
+                            checked
+                            {
+                                while (await e.MoveNextAsync().ConfigureAwait(false))
+                                {
+                                    v = _selector(e.Current);
+                                    if (v.HasValue)
+                                    {
+                                        sum += v.GetValueOrDefault();
+                                        ++count;
+                                    }
+                                }
+                            }
+
+                            return <#=res#>;
+                        }
+                    }
+                }
+                finally
+                {
+                    await e.DisposeAsync().ConfigureAwait(false);
+                }
+
+                return null;
+<#
+}
+else
+{
+#>
+                var e = _source.GetAsyncEnumerator(_cancellationToken);
+
+                try
+                {
+                    if (!await e.MoveNextAsync().ConfigureAwait(false))
+                    {
+                        throw Error.NoElements();
+                    }
+
+                    <#=o.sum#> sum = _selector(e.Current);
+                    long count = 1;
+                    checked
+                    {
+                        while (await e.MoveNextAsync().ConfigureAwait(false))
+                        {
+                            sum += _selector(e.Current);
+                            ++count;
+                        }
+                    }
+
+                    return <#=res#>;
+                }
+                finally
+                {
+                    await e.DisposeAsync().ConfigureAwait(false);
+                }
+<#
+}
+#>
+            }
         }
 
         public static Task<<#=o.res#>> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<<#=o.type#>>> selector, CancellationToken cancellationToken = default)
@@ -60,7 +222,83 @@ foreach (var o in os)
             if (selector == null)
                 throw Error.ArgumentNull(nameof(selector));
 
-            return AverageCore(source, selector, cancellationToken);
+            return Core(source, selector, cancellationToken);
+
+            async Task<<#=o.res#>> Core(IAsyncEnumerable<TSource> _source, Func<TSource, ValueTask<<#=o.type#>>> _selector, CancellationToken _cancellationToken)
+            {
+<#
+if (isNullable)
+{
+#>
+                var e = _source.GetAsyncEnumerator(_cancellationToken);
+
+                try
+                {
+                    while (await e.MoveNextAsync().ConfigureAwait(false))
+                    {
+                        var v = await _selector(e.Current).ConfigureAwait(false);
+                        if (v.HasValue)
+                        {
+                            <#=o.sum#> sum = v.GetValueOrDefault();
+                            long count = 1;
+                            checked
+                            {
+                                while (await e.MoveNextAsync().ConfigureAwait(false))
+                                {
+                                    v = await _selector(e.Current).ConfigureAwait(false);
+                                    if (v.HasValue)
+                                    {
+                                        sum += v.GetValueOrDefault();
+                                        ++count;
+                                    }
+                                }
+                            }
+
+                            return <#=res#>;
+                        }
+                    }
+                }
+                finally
+                {
+                    await e.DisposeAsync().ConfigureAwait(false);
+                }
+
+                return null;
+<#
+}
+else
+{
+#>
+                var e = _source.GetAsyncEnumerator(_cancellationToken);
+
+                try
+                {
+                    if (!await e.MoveNextAsync().ConfigureAwait(false))
+                    {
+                        throw Error.NoElements();
+                    }
+
+                    <#=o.sum#> sum = await _selector(e.Current).ConfigureAwait(false);
+                    long count = 1;
+                    checked
+                    {
+                        while (await e.MoveNextAsync().ConfigureAwait(false))
+                        {
+                            sum += await _selector(e.Current).ConfigureAwait(false);
+                            ++count;
+                        }
+                    }
+
+                    return <#=res#>;
+                }
+                finally
+                {
+                    await e.DisposeAsync().ConfigureAwait(false);
+                }
+<#
+}
+#>
+            }
         }
 
 #if !NO_DEEP_CANCELLATION
@@ -71,7 +309,83 @@ foreach (var o in os)
             if (selector == null)
                 throw Error.ArgumentNull(nameof(selector));
 
-            return AverageCore(source, selector, cancellationToken);
+            return Core(source, selector, cancellationToken);
+
+            async Task<<#=o.res#>> Core(IAsyncEnumerable<TSource> _source, Func<TSource, CancellationToken, ValueTask<<#=o.type#>>> _selector, CancellationToken _cancellationToken)
+            {
+<#
+if (isNullable)
+{
+#>
+                var e = _source.GetAsyncEnumerator(_cancellationToken);
+
+                try
+                {
+                    while (await e.MoveNextAsync().ConfigureAwait(false))
+                    {
+                        var v = await _selector(e.Current, _cancellationToken).ConfigureAwait(false);
+                        if (v.HasValue)
+                        {
+                            <#=o.sum#> sum = v.GetValueOrDefault();
+                            long count = 1;
+                            checked
+                            {
+                                while (await e.MoveNextAsync().ConfigureAwait(false))
+                                {
+                                    v = await _selector(e.Current, _cancellationToken).ConfigureAwait(false);
+                                    if (v.HasValue)
+                                    {
+                                        sum += v.GetValueOrDefault();
+                                        ++count;
+                                    }
+                                }
+                            }
+
+                            return <#=res#>;
+                        }
+                    }
+                }
+                finally
+                {
+                    await e.DisposeAsync().ConfigureAwait(false);
+                }
+
+                return null;
+<#
+}
+else
+{
+#>
+                var e = _source.GetAsyncEnumerator(_cancellationToken);
+
+                try
+                {
+                    if (!await e.MoveNextAsync().ConfigureAwait(false))
+                    {
+                        throw Error.NoElements();
+                    }
+
+                    <#=o.sum#> sum = await _selector(e.Current, _cancellationToken).ConfigureAwait(false);
+                    long count = 1;
+                    checked
+                    {
+                        while (await e.MoveNextAsync().ConfigureAwait(false))
+                        {
+                            sum += await _selector(e.Current, _cancellationToken).ConfigureAwait(false);
+                            ++count;
+                        }
+                    }
+
+                    return <#=res#>;
+                }
+                finally
+                {
+                    await e.DisposeAsync().ConfigureAwait(false);
+                }
+<#
+}
+#>
+            }
         }
 #endif
 

+ 0 - 1357
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Average.cs

@@ -1,1357 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the Apache 2.0 License.
-// See the LICENSE file in the project root for more information. 
-
-using System.Collections.Generic;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace System.Linq
-{
-    public static partial class AsyncEnumerable
-    {
-        private static async Task<double> AverageCore(this IAsyncEnumerable<int> source, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                if (!await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    throw Error.NoElements();
-                }
-
-                long sum = e.Current;
-                long count = 1;
-                checked
-                {
-                    while (await e.MoveNextAsync().ConfigureAwait(false))
-                    {
-                        sum += e.Current;
-                        ++count;
-                    }
-                }
-
-                return (double)sum / count;
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-        }
-
-        private static async Task<double> AverageCore<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                if (!await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    throw Error.NoElements();
-                }
-
-                long sum = selector(e.Current);
-                long count = 1;
-                checked
-                {
-                    while (await e.MoveNextAsync().ConfigureAwait(false))
-                    {
-                        sum += selector(e.Current);
-                        ++count;
-                    }
-                }
-
-                return (double)sum / count;
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-        }
-
-        private static async Task<double> AverageCore<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<int>> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                if (!await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    throw Error.NoElements();
-                }
-
-                long sum = await selector(e.Current).ConfigureAwait(false);
-                long count = 1;
-                checked
-                {
-                    while (await e.MoveNextAsync().ConfigureAwait(false))
-                    {
-                        sum += await selector(e.Current).ConfigureAwait(false);
-                        ++count;
-                    }
-                }
-
-                return (double)sum / count;
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private static async Task<double> AverageCore<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<int>> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                if (!await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    throw Error.NoElements();
-                }
-
-                long sum = await selector(e.Current, cancellationToken).ConfigureAwait(false);
-                long count = 1;
-                checked
-                {
-                    while (await e.MoveNextAsync().ConfigureAwait(false))
-                    {
-                        sum += await selector(e.Current, cancellationToken).ConfigureAwait(false);
-                        ++count;
-                    }
-                }
-
-                return (double)sum / count;
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-        }
-#endif
-
-        private static async Task<double?> AverageCore(IAsyncEnumerable<int?> source, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    var v = e.Current;
-                    if (v.HasValue)
-                    {
-                        long sum = v.GetValueOrDefault();
-                        long count = 1;
-                        checked
-                        {
-                            while (await e.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                v = e.Current;
-                                if (v.HasValue)
-                                {
-                                    sum += v.GetValueOrDefault();
-                                    ++count;
-                                }
-                            }
-                        }
-
-                        return (double)sum / count;
-                    }
-                }
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-
-            return null;
-        }
-
-        private static async Task<double?> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, int?> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    var v = selector(e.Current);
-                    if (v.HasValue)
-                    {
-                        long sum = v.GetValueOrDefault();
-                        long count = 1;
-                        checked
-                        {
-                            while (await e.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                v = selector(e.Current);
-                                if (v.HasValue)
-                                {
-                                    sum += v.GetValueOrDefault();
-                                    ++count;
-                                }
-                            }
-                        }
-
-                        return (double)sum / count;
-                    }
-                }
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-
-            return null;
-        }
-
-        private static async Task<double?> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<int?>> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    var v = await selector(e.Current).ConfigureAwait(false);
-                    if (v.HasValue)
-                    {
-                        long sum = v.GetValueOrDefault();
-                        long count = 1;
-                        checked
-                        {
-                            while (await e.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                v = await selector(e.Current).ConfigureAwait(false);
-                                if (v.HasValue)
-                                {
-                                    sum += v.GetValueOrDefault();
-                                    ++count;
-                                }
-                            }
-                        }
-
-                        return (double)sum / count;
-                    }
-                }
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-
-            return null;
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private static async Task<double?> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<int?>> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    var v = await selector(e.Current, cancellationToken).ConfigureAwait(false);
-                    if (v.HasValue)
-                    {
-                        long sum = v.GetValueOrDefault();
-                        long count = 1;
-                        checked
-                        {
-                            while (await e.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                v = await selector(e.Current, cancellationToken).ConfigureAwait(false);
-                                if (v.HasValue)
-                                {
-                                    sum += v.GetValueOrDefault();
-                                    ++count;
-                                }
-                            }
-                        }
-
-                        return (double)sum / count;
-                    }
-                }
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-
-            return null;
-        }
-#endif
-
-        private static async Task<double> AverageCore(IAsyncEnumerable<long> source, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                if (!await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    throw Error.NoElements();
-                }
-
-                var sum = e.Current;
-                long count = 1;
-                checked
-                {
-                    while (await e.MoveNextAsync().ConfigureAwait(false))
-                    {
-                        sum += e.Current;
-                        ++count;
-                    }
-                }
-
-                return (double)sum / count;
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-        }
-
-        private static async Task<double> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, long> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                if (!await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    throw Error.NoElements();
-                }
-
-                var sum = selector(e.Current);
-                long count = 1;
-                checked
-                {
-                    while (await e.MoveNextAsync().ConfigureAwait(false))
-                    {
-                        sum += selector(e.Current);
-                        ++count;
-                    }
-                }
-
-                return (double)sum / count;
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-        }
-
-        private static async Task<double> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<long>> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                if (!await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    throw Error.NoElements();
-                }
-
-                var sum = await selector(e.Current).ConfigureAwait(false);
-                long count = 1;
-                checked
-                {
-                    while (await e.MoveNextAsync().ConfigureAwait(false))
-                    {
-                        sum += await selector(e.Current).ConfigureAwait(false);
-                        ++count;
-                    }
-                }
-
-                return (double)sum / count;
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private static async Task<double> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<long>> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                if (!await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    throw Error.NoElements();
-                }
-
-                var sum = await selector(e.Current, cancellationToken).ConfigureAwait(false);
-                long count = 1;
-                checked
-                {
-                    while (await e.MoveNextAsync().ConfigureAwait(false))
-                    {
-                        sum += await selector(e.Current, cancellationToken).ConfigureAwait(false);
-                        ++count;
-                    }
-                }
-
-                return (double)sum / count;
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-        }
-#endif
-
-        private static async Task<double?> AverageCore(IAsyncEnumerable<long?> source, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    var v = e.Current;
-                    if (v.HasValue)
-                    {
-                        var sum = v.GetValueOrDefault();
-                        long count = 1;
-                        checked
-                        {
-                            while (await e.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                v = e.Current;
-                                if (v.HasValue)
-                                {
-                                    sum += v.GetValueOrDefault();
-                                    ++count;
-                                }
-                            }
-                        }
-
-                        return (double)sum / count;
-                    }
-                }
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-
-            return null;
-        }
-
-        private static async Task<double?> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, long?> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    var v = selector(e.Current);
-                    if (v.HasValue)
-                    {
-                        var sum = v.GetValueOrDefault();
-                        long count = 1;
-                        checked
-                        {
-                            while (await e.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                v = selector(e.Current);
-                                if (v.HasValue)
-                                {
-                                    sum += v.GetValueOrDefault();
-                                    ++count;
-                                }
-                            }
-                        }
-
-                        return (double)sum / count;
-                    }
-                }
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-
-            return null;
-        }
-
-        private static async Task<double?> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<long?>> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    var v = await selector(e.Current).ConfigureAwait(false);
-                    if (v.HasValue)
-                    {
-                        var sum = v.GetValueOrDefault();
-                        long count = 1;
-                        checked
-                        {
-                            while (await e.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                v = await selector(e.Current).ConfigureAwait(false);
-                                if (v.HasValue)
-                                {
-                                    sum += v.GetValueOrDefault();
-                                    ++count;
-                                }
-                            }
-                        }
-
-                        return (double)sum / count;
-                    }
-                }
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-
-            return null;
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private static async Task<double?> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<long?>> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    var v = await selector(e.Current, cancellationToken).ConfigureAwait(false);
-                    if (v.HasValue)
-                    {
-                        var sum = v.GetValueOrDefault();
-                        long count = 1;
-                        checked
-                        {
-                            while (await e.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                v = await selector(e.Current, cancellationToken).ConfigureAwait(false);
-                                if (v.HasValue)
-                                {
-                                    sum += v.GetValueOrDefault();
-                                    ++count;
-                                }
-                            }
-                        }
-
-                        return (double)sum / count;
-                    }
-                }
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-
-            return null;
-        }
-#endif
-
-        private static async Task<double> AverageCore(IAsyncEnumerable<double> source, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                if (!await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    throw Error.NoElements();
-                }
-
-                var sum = e.Current;
-                long count = 1;
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    // There is an opportunity to short-circuit here, in that if e.Current is
-                    // ever NaN then the result will always be NaN. Assuming that this case is
-                    // rare enough that not checking is the better approach generally.
-                    sum += e.Current;
-                    ++count;
-                }
-
-                return sum / count;
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-        }
-
-        private static async Task<double> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, double> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                if (!await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    throw Error.NoElements();
-                }
-
-                var sum = selector(e.Current);
-                long count = 1;
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    // There is an opportunity to short-circuit here, in that if e.Current is
-                    // ever NaN then the result will always be NaN. Assuming that this case is
-                    // rare enough that not checking is the better approach generally.
-                    sum += selector(e.Current);
-                    ++count;
-                }
-
-                return sum / count;
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-        }
-
-        private static async Task<double> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<double>> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                if (!await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    throw Error.NoElements();
-                }
-
-                var sum = await selector(e.Current).ConfigureAwait(false);
-                long count = 1;
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    // There is an opportunity to short-circuit here, in that if e.Current is
-                    // ever NaN then the result will always be NaN. Assuming that this case is
-                    // rare enough that not checking is the better approach generally.
-                    sum += await selector(e.Current).ConfigureAwait(false);
-                    ++count;
-                }
-
-                return sum / count;
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private static async Task<double> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<double>> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                if (!await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    throw Error.NoElements();
-                }
-
-                var sum = await selector(e.Current, cancellationToken).ConfigureAwait(false);
-                long count = 1;
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    // There is an opportunity to short-circuit here, in that if e.Current is
-                    // ever NaN then the result will always be NaN. Assuming that this case is
-                    // rare enough that not checking is the better approach generally.
-                    sum += await selector(e.Current, cancellationToken).ConfigureAwait(false);
-                    ++count;
-                }
-
-                return sum / count;
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-        }
-#endif
-
-        private static async Task<double?> AverageCore(IAsyncEnumerable<double?> source, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    var v = e.Current;
-                    if (v.HasValue)
-                    {
-                        var sum = v.GetValueOrDefault();
-                        long count = 1;
-                        checked
-                        {
-                            while (await e.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                v = e.Current;
-                                if (v.HasValue)
-                                {
-                                    sum += v.GetValueOrDefault();
-                                    ++count;
-                                }
-                            }
-                        }
-
-                        return sum / count;
-                    }
-                }
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-
-            return null;
-        }
-
-        private static async Task<double?> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, double?> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    var v = selector(e.Current);
-                    if (v.HasValue)
-                    {
-                        var sum = v.GetValueOrDefault();
-                        long count = 1;
-                        checked
-                        {
-                            while (await e.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                v = selector(e.Current);
-                                if (v.HasValue)
-                                {
-                                    sum += v.GetValueOrDefault();
-                                    ++count;
-                                }
-                            }
-                        }
-
-                        return sum / count;
-                    }
-                }
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-
-            return null;
-        }
-
-        private static async Task<double?> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<double?>> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    var v = await selector(e.Current).ConfigureAwait(false);
-                    if (v.HasValue)
-                    {
-                        var sum = v.GetValueOrDefault();
-                        long count = 1;
-                        checked
-                        {
-                            while (await e.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                v = await selector(e.Current).ConfigureAwait(false);
-                                if (v.HasValue)
-                                {
-                                    sum += v.GetValueOrDefault();
-                                    ++count;
-                                }
-                            }
-                        }
-
-                        return sum / count;
-                    }
-                }
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-
-            return null;
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private static async Task<double?> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<double?>> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    var v = await selector(e.Current, cancellationToken).ConfigureAwait(false);
-                    if (v.HasValue)
-                    {
-                        var sum = v.GetValueOrDefault();
-                        long count = 1;
-                        checked
-                        {
-                            while (await e.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                v = await selector(e.Current, cancellationToken).ConfigureAwait(false);
-                                if (v.HasValue)
-                                {
-                                    sum += v.GetValueOrDefault();
-                                    ++count;
-                                }
-                            }
-                        }
-
-                        return sum / count;
-                    }
-                }
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-
-            return null;
-        }
-#endif
-
-        private static async Task<float> AverageCore(IAsyncEnumerable<float> source, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                if (!await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    throw Error.NoElements();
-                }
-
-                double sum = e.Current;
-                long count = 1;
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    sum += e.Current;
-                    ++count;
-                }
-
-                return (float)(sum / count);
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-        }
-
-        private static async Task<float> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, float> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                if (!await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    throw Error.NoElements();
-                }
-
-                double sum = selector(e.Current);
-                long count = 1;
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    sum += selector(e.Current);
-                    ++count;
-                }
-
-                return (float)(sum / count);
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-        }
-
-        private static async Task<float> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<float>> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                if (!await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    throw Error.NoElements();
-                }
-
-                double sum = await selector(e.Current).ConfigureAwait(false);
-                long count = 1;
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    sum += await selector(e.Current).ConfigureAwait(false);
-                    ++count;
-                }
-
-                return (float)(sum / count);
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private static async Task<float> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<float>> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                if (!await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    throw Error.NoElements();
-                }
-
-                double sum = await selector(e.Current, cancellationToken).ConfigureAwait(false);
-                long count = 1;
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    sum += await selector(e.Current, cancellationToken).ConfigureAwait(false);
-                    ++count;
-                }
-
-                return (float)(sum / count);
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-        }
-#endif
-
-        private static async Task<float?> AverageCore(IAsyncEnumerable<float?> source, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    var v = e.Current;
-                    if (v.HasValue)
-                    {
-                        double sum = v.GetValueOrDefault();
-                        long count = 1;
-                        checked
-                        {
-                            while (await e.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                v = e.Current;
-                                if (v.HasValue)
-                                {
-                                    sum += v.GetValueOrDefault();
-                                    ++count;
-                                }
-                            }
-                        }
-
-                        return (float)(sum / count);
-                    }
-                }
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-
-            return null;
-        }
-
-        private static async Task<float?> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, float?> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    var v = selector(e.Current);
-                    if (v.HasValue)
-                    {
-                        double sum = v.GetValueOrDefault();
-                        long count = 1;
-                        checked
-                        {
-                            while (await e.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                v = selector(e.Current);
-                                if (v.HasValue)
-                                {
-                                    sum += v.GetValueOrDefault();
-                                    ++count;
-                                }
-                            }
-                        }
-
-                        return (float)(sum / count);
-                    }
-                }
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-
-            return null;
-        }
-
-        private static async Task<float?> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<float?>> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    var v = await selector(e.Current).ConfigureAwait(false);
-                    if (v.HasValue)
-                    {
-                        double sum = v.GetValueOrDefault();
-                        long count = 1;
-                        checked
-                        {
-                            while (await e.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                v = await selector(e.Current).ConfigureAwait(false);
-                                if (v.HasValue)
-                                {
-                                    sum += v.GetValueOrDefault();
-                                    ++count;
-                                }
-                            }
-                        }
-
-                        return (float)(sum / count);
-                    }
-                }
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-
-            return null;
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private static async Task<float?> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<float?>> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    var v = await selector(e.Current, cancellationToken).ConfigureAwait(false);
-                    if (v.HasValue)
-                    {
-                        double sum = v.GetValueOrDefault();
-                        long count = 1;
-                        checked
-                        {
-                            while (await e.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                v = await selector(e.Current, cancellationToken).ConfigureAwait(false);
-                                if (v.HasValue)
-                                {
-                                    sum += v.GetValueOrDefault();
-                                    ++count;
-                                }
-                            }
-                        }
-
-                        return (float)(sum / count);
-                    }
-                }
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-
-            return null;
-        }
-#endif
-
-        private static async Task<decimal> AverageCore(IAsyncEnumerable<decimal> source, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                if (!await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    throw Error.NoElements();
-                }
-
-                var sum = e.Current;
-                long count = 1;
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    sum += e.Current;
-                    ++count;
-                }
-
-                return sum / count;
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-        }
-
-        private static async Task<decimal> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, decimal> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                if (!await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    throw Error.NoElements();
-                }
-
-                var sum = selector(e.Current);
-                long count = 1;
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    sum += selector(e.Current);
-                    ++count;
-                }
-
-                return sum / count;
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-        }
-
-        private static async Task<decimal> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<decimal>> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                if (!await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    throw Error.NoElements();
-                }
-
-                var sum = await selector(e.Current).ConfigureAwait(false);
-                long count = 1;
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    sum += await selector(e.Current).ConfigureAwait(false);
-                    ++count;
-                }
-
-                return sum / count;
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private static async Task<decimal> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<decimal>> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                if (!await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    throw Error.NoElements();
-                }
-
-                var sum = await selector(e.Current, cancellationToken).ConfigureAwait(false);
-                long count = 1;
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    sum += await selector(e.Current, cancellationToken).ConfigureAwait(false);
-                    ++count;
-                }
-
-                return sum / count;
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-        }
-#endif
-
-        private static async Task<decimal?> AverageCore(IAsyncEnumerable<decimal?> source, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    var v = e.Current;
-                    if (v.HasValue)
-                    {
-                        var sum = v.GetValueOrDefault();
-                        long count = 1;
-                        while (await e.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            v = e.Current;
-                            if (v.HasValue)
-                            {
-                                sum += v.GetValueOrDefault();
-                                ++count;
-                            }
-                        }
-
-                        return sum / count;
-                    }
-                }
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-
-            return null;
-        }
-
-        private static async Task<decimal?> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, decimal?> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    var v = selector(e.Current);
-                    if (v.HasValue)
-                    {
-                        var sum = v.GetValueOrDefault();
-                        long count = 1;
-                        while (await e.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            v = selector(e.Current);
-                            if (v.HasValue)
-                            {
-                                sum += v.GetValueOrDefault();
-                                ++count;
-                            }
-                        }
-
-                        return sum / count;
-                    }
-                }
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-
-            return null;
-        }
-
-        private static async Task<decimal?> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<decimal?>> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    var v = await selector(e.Current).ConfigureAwait(false);
-                    if (v.HasValue)
-                    {
-                        var sum = v.GetValueOrDefault();
-                        long count = 1;
-                        while (await e.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            v = await selector(e.Current).ConfigureAwait(false);
-                            if (v.HasValue)
-                            {
-                                sum += v.GetValueOrDefault();
-                                ++count;
-                            }
-                        }
-
-                        return sum / count;
-                    }
-                }
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-
-            return null;
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private static async Task<decimal?> AverageCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<decimal?>> selector, CancellationToken cancellationToken)
-        {
-            var e = source.GetAsyncEnumerator(cancellationToken);
-
-            try
-            {
-                while (await e.MoveNextAsync().ConfigureAwait(false))
-                {
-                    var v = await selector(e.Current, cancellationToken).ConfigureAwait(false);
-                    if (v.HasValue)
-                    {
-                        var sum = v.GetValueOrDefault();
-                        long count = 1;
-                        while (await e.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            v = await selector(e.Current, cancellationToken).ConfigureAwait(false);
-                            if (v.HasValue)
-                            {
-                                sum += v.GetValueOrDefault();
-                                ++count;
-                            }
-                        }
-
-                        return sum / count;
-                    }
-                }
-            }
-            finally
-            {
-                await e.DisposeAsync().ConfigureAwait(false);
-            }
-
-            return null;
-        }
-#endif
-    }
-}

Some files were not shown because too many files changed in this diff