Skip to content

Commit

Permalink
Implement Average overloads with selector.
Browse files Browse the repository at this point in the history
  • Loading branch information
bartdesmet committed Nov 15, 2018
1 parent 6f9f24e commit 568e78f
Show file tree
Hide file tree
Showing 3 changed files with 750 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(CancellationToken.None);
return AverageCore(source, selector, CancellationToken.None);
}

public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int> selector, CancellationToken cancellationToken)
Expand All @@ -43,7 +43,7 @@ public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(cancellationToken);
return AverageCore(source, selector, cancellationToken);
}

public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<int>> selector)
Expand All @@ -53,7 +53,7 @@ public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(CancellationToken.None);
return AverageCore(source, selector, CancellationToken.None);
}

public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<int>> selector, CancellationToken cancellationToken)
Expand All @@ -63,7 +63,7 @@ public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(cancellationToken);
return AverageCore(source, selector, cancellationToken);
}

public static Task<double> AverageAsync(this IAsyncEnumerable<long> source)
Expand All @@ -89,7 +89,7 @@ public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(CancellationToken.None);
return AverageCore(source, selector, CancellationToken.None);
}

public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long> selector, CancellationToken cancellationToken)
Expand All @@ -99,7 +99,7 @@ public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(cancellationToken);
return AverageCore(source, selector, cancellationToken);
}

public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<long>> selector)
Expand All @@ -109,7 +109,7 @@ public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(CancellationToken.None);
return AverageCore(source, selector, CancellationToken.None);
}

public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<long>> selector, CancellationToken cancellationToken)
Expand All @@ -119,7 +119,7 @@ public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(cancellationToken);
return AverageCore(source, selector, cancellationToken);
}

public static Task<float> AverageAsync(this IAsyncEnumerable<float> source)
Expand All @@ -145,7 +145,7 @@ public static Task<float> AverageAsync<TSource>(this IAsyncEnumerable<TSource> s
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(CancellationToken.None);
return AverageCore(source, selector, CancellationToken.None);
}

public static Task<float> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float> selector, CancellationToken cancellationToken)
Expand All @@ -155,7 +155,7 @@ public static Task<float> AverageAsync<TSource>(this IAsyncEnumerable<TSource> s
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(cancellationToken);
return AverageCore(source, selector, cancellationToken);
}

public static Task<float> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<float>> selector)
Expand All @@ -165,7 +165,7 @@ public static Task<float> AverageAsync<TSource>(this IAsyncEnumerable<TSource> s
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(CancellationToken.None);
return AverageCore(source, selector, CancellationToken.None);
}

public static Task<float> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<float>> selector, CancellationToken cancellationToken)
Expand All @@ -175,7 +175,7 @@ public static Task<float> AverageAsync<TSource>(this IAsyncEnumerable<TSource> s
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(cancellationToken);
return AverageCore(source, selector, cancellationToken);
}

public static Task<double> AverageAsync(this IAsyncEnumerable<double> source)
Expand All @@ -201,7 +201,7 @@ public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(CancellationToken.None);
return AverageCore(source, selector, CancellationToken.None);
}

public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double> selector, CancellationToken cancellationToken)
Expand All @@ -211,7 +211,7 @@ public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(cancellationToken);
return AverageCore(source, selector, cancellationToken);
}

public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<double>> selector)
Expand All @@ -221,7 +221,7 @@ public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(CancellationToken.None);
return AverageCore(source, selector, CancellationToken.None);
}

public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<double>> selector, CancellationToken cancellationToken)
Expand All @@ -231,7 +231,7 @@ public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(cancellationToken);
return AverageCore(source, selector, cancellationToken);
}

public static Task<decimal> AverageAsync(this IAsyncEnumerable<decimal> source)
Expand All @@ -257,7 +257,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(CancellationToken.None);
return AverageCore(source, selector, CancellationToken.None);
}

public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal> selector, CancellationToken cancellationToken)
Expand All @@ -267,7 +267,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(cancellationToken);
return AverageCore(source, selector, cancellationToken);
}

public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<decimal>> selector)
Expand All @@ -277,7 +277,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(CancellationToken.None);
return AverageCore(source, selector, CancellationToken.None);
}

public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<decimal>> selector, CancellationToken cancellationToken)
Expand All @@ -287,7 +287,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(cancellationToken);
return AverageCore(source, selector, cancellationToken);
}

public static Task<double?> AverageAsync(this IAsyncEnumerable<int?> source)
Expand All @@ -313,7 +313,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(CancellationToken.None);
return AverageCore(source, selector, CancellationToken.None);
}

public static Task<double?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int?> selector, CancellationToken cancellationToken)
Expand All @@ -323,7 +323,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(cancellationToken);
return AverageCore(source, selector, cancellationToken);
}

public static Task<double?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<int?>> selector)
Expand All @@ -333,7 +333,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(CancellationToken.None);
return AverageCore(source, selector, CancellationToken.None);
}

public static Task<double?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<int?>> selector, CancellationToken cancellationToken)
Expand All @@ -343,7 +343,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(cancellationToken);
return AverageCore(source, selector, cancellationToken);
}

public static Task<double?> AverageAsync(this IAsyncEnumerable<long?> source)
Expand All @@ -369,7 +369,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(CancellationToken.None);
return AverageCore(source, selector, CancellationToken.None);
}

public static Task<double?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long?> selector, CancellationToken cancellationToken)
Expand All @@ -379,7 +379,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(cancellationToken);
return AverageCore(source, selector, cancellationToken);
}

public static Task<double?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<long?>> selector)
Expand All @@ -389,7 +389,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(CancellationToken.None);
return AverageCore(source, selector, CancellationToken.None);
}

public static Task<double?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<long?>> selector, CancellationToken cancellationToken)
Expand All @@ -399,7 +399,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(cancellationToken);
return AverageCore(source, selector, cancellationToken);
}

public static Task<float?> AverageAsync(this IAsyncEnumerable<float?> source)
Expand All @@ -425,7 +425,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(CancellationToken.None);
return AverageCore(source, selector, CancellationToken.None);
}

public static Task<float?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float?> selector, CancellationToken cancellationToken)
Expand All @@ -435,7 +435,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(cancellationToken);
return AverageCore(source, selector, cancellationToken);
}

public static Task<float?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<float?>> selector)
Expand All @@ -445,7 +445,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(CancellationToken.None);
return AverageCore(source, selector, CancellationToken.None);
}

public static Task<float?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<float?>> selector, CancellationToken cancellationToken)
Expand All @@ -455,7 +455,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(cancellationToken);
return AverageCore(source, selector, cancellationToken);
}

public static Task<double?> AverageAsync(this IAsyncEnumerable<double?> source)
Expand All @@ -481,7 +481,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(CancellationToken.None);
return AverageCore(source, selector, CancellationToken.None);
}

public static Task<double?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double?> selector, CancellationToken cancellationToken)
Expand All @@ -491,7 +491,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(cancellationToken);
return AverageCore(source, selector, cancellationToken);
}

public static Task<double?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<double?>> selector)
Expand All @@ -501,7 +501,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(CancellationToken.None);
return AverageCore(source, selector, CancellationToken.None);
}

public static Task<double?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<double?>> selector, CancellationToken cancellationToken)
Expand All @@ -511,7 +511,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(cancellationToken);
return AverageCore(source, selector, cancellationToken);
}

public static Task<decimal?> AverageAsync(this IAsyncEnumerable<decimal?> source)
Expand All @@ -537,7 +537,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(CancellationToken.None);
return AverageCore(source, selector, CancellationToken.None);
}

public static Task<decimal?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal?> selector, CancellationToken cancellationToken)
Expand All @@ -547,7 +547,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(cancellationToken);
return AverageCore(source, selector, cancellationToken);
}

public static Task<decimal?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<decimal?>> selector)
Expand All @@ -557,7 +557,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(CancellationToken.None);
return AverageCore(source, selector, CancellationToken.None);
}

public static Task<decimal?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<decimal?>> selector, CancellationToken cancellationToken)
Expand All @@ -567,7 +567,7 @@ public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource>
if (selector == null)
throw Error.ArgumentNull(nameof(selector));

return source.Select(selector).AverageAsync(cancellationToken);
return AverageCore(source, selector, cancellationToken);
}

}
Expand Down
Loading

0 comments on commit 568e78f

Please sign in to comment.