1
0

StartWith.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT License.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Collections.Generic;
  5. namespace System.Linq
  6. {
  7. public static partial class AsyncEnumerableEx
  8. {
  9. // REVIEW: This is really an n-ary Prepend. Should we add n-ary overloads of Append and Prepend as well?
  10. // If so, likely in Ix rather than System.Linq.Async.
  11. /// <summary>
  12. /// Prepends a sequence of values to an async-enumerable sequence.
  13. /// </summary>
  14. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  15. /// <param name="source">Source sequence to prepend values to.</param>
  16. /// <param name="values">Values to prepend to the specified sequence.</param>
  17. /// <returns>The source sequence prepended with the specified values.</returns>
  18. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="values"/> is null.</exception>
  19. public static IAsyncEnumerable<TSource> StartWith<TSource>(this IAsyncEnumerable<TSource> source, params TSource[] values)
  20. {
  21. if (source == null)
  22. throw Error.ArgumentNull(nameof(source));
  23. if (values == null)
  24. throw Error.ArgumentNull(nameof(values));
  25. return values.ToAsyncEnumerable().Concat(source);
  26. }
  27. }
  28. }