Use source generator to generate Zip overloads

This commit is contained in:
Ruben Schmidmeister 2021-06-22 19:50:10 +02:00
Родитель 8c85e825a7
Коммит 0cbfe65d22
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B3B879F0A0AF19C3
2 изменённых файлов: 15 добавлений и 19 удалений

Просмотреть файл

@ -11,27 +11,10 @@ namespace System.Linq
partial class AsyncEnumerable
{
#if SUPPORT_FLAT_ASYNC_API
public static IAsyncEnumerable<TResult> Zip<TFirst, TSecond, TResult>(this IAsyncEnumerable<TFirst> first, IAsyncEnumerable<TSecond> second, Func<TFirst, TSecond, ValueTask<TResult>> selector) => ZipAwaitCore<TFirst, TSecond, TResult>(first, second, selector);
#if !NO_DEEP_CANCELLATION
public static IAsyncEnumerable<TResult> Zip<TFirst, TSecond, TResult>(this IAsyncEnumerable<TFirst> first, IAsyncEnumerable<TSecond> second, Func<TFirst, TSecond, CancellationToken, ValueTask<TResult>> selector) => ZipAwaitWithCancellationCore<TFirst, TSecond, TResult>(first, second, selector);
#endif
#else
/// <summary>
/// Merges two async-enumerable sequences into one async-enumerable sequence by combining their elements in a pairwise fashion.
/// </summary>
/// <typeparam name="TFirst">The type of the elements in the first source sequence.</typeparam>
/// <typeparam name="TSecond">The type of the elements in the second source sequence.</typeparam>
/// <typeparam name="TResult">The type of the elements in the result sequence, returned by the selector function.</typeparam>
/// <param name="first">First async-enumerable source.</param>
/// <param name="second">Second async-enumerable source.</param>
/// <param name="selector">An asynchronous function to invoke and await for each consecutive pair of elements from the first and second source.</param>
/// <returns>An async-enumerable sequence containing the result of pairwise combining the elements of the first and second source using the specified result selector function.</returns>
/// <exception cref="ArgumentNullException"><paramref name="first"/> or <paramref name="second"/> or <paramref name="selector"/> is null.</exception>
public static IAsyncEnumerable<TResult> ZipAwait<TFirst, TSecond, TResult>(this IAsyncEnumerable<TFirst> first, IAsyncEnumerable<TSecond> second, Func<TFirst, TSecond, ValueTask<TResult>> selector) => ZipAwaitCore<TFirst, TSecond, TResult>(first, second, selector);
#if !NO_DEEP_CANCELLATION
public static IAsyncEnumerable<TResult> ZipAwaitWithCancellation<TFirst, TSecond, TResult>(this IAsyncEnumerable<TFirst> first, IAsyncEnumerable<TSecond> second, Func<TFirst, TSecond, CancellationToken, ValueTask<TResult>> selector) => ZipAwaitWithCancellationCore<TFirst, TSecond, TResult>(first, second, selector);
#endif
#endif
}

Просмотреть файл

@ -67,7 +67,19 @@ namespace System.Linq
}
}
internal static IAsyncEnumerable<TResult> ZipAwaitCore<TFirst, TSecond, TResult>(this IAsyncEnumerable<TFirst> first, IAsyncEnumerable<TSecond> second, Func<TFirst, TSecond, ValueTask<TResult>> selector)
/// <summary>
/// Merges two async-enumerable sequences into one async-enumerable sequence by combining their elements in a pairwise fashion.
/// </summary>
/// <typeparam name="TFirst">The type of the elements in the first source sequence.</typeparam>
/// <typeparam name="TSecond">The type of the elements in the second source sequence.</typeparam>
/// <typeparam name="TResult">The type of the elements in the result sequence, returned by the selector function.</typeparam>
/// <param name="first">First async-enumerable source.</param>
/// <param name="second">Second async-enumerable source.</param>
/// <param name="selector">An asynchronous function to invoke and await for each consecutive pair of elements from the first and second source.</param>
/// <returns>An async-enumerable sequence containing the result of pairwise combining the elements of the first and second source using the specified result selector function.</returns>
/// <exception cref="ArgumentNullException"><paramref name="first"/> or <paramref name="second"/> or <paramref name="selector"/> is null.</exception>
[GenerateAsyncOverload]
private static IAsyncEnumerable<TResult> ZipAwaitCore<TFirst, TSecond, TResult>(this IAsyncEnumerable<TFirst> first, IAsyncEnumerable<TSecond> second, Func<TFirst, TSecond, ValueTask<TResult>> selector)
{
if (first == null)
throw Error.ArgumentNull(nameof(first));
@ -91,7 +103,8 @@ namespace System.Linq
}
#if !NO_DEEP_CANCELLATION
internal static IAsyncEnumerable<TResult> ZipAwaitWithCancellationCore<TFirst, TSecond, TResult>(this IAsyncEnumerable<TFirst> first, IAsyncEnumerable<TSecond> second, Func<TFirst, TSecond, CancellationToken, ValueTask<TResult>> selector)
[GenerateAsyncOverload]
private static IAsyncEnumerable<TResult> ZipAwaitWithCancellationCore<TFirst, TSecond, TResult>(this IAsyncEnumerable<TFirst> first, IAsyncEnumerable<TSecond> second, Func<TFirst, TSecond, CancellationToken, ValueTask<TResult>> selector)
{
if (first == null)
throw Error.ArgumentNull(nameof(first));