IOrderedAsyncEnumerable.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. using System.Threading;
  6. using System.Threading.Tasks;
  7. namespace System.Linq
  8. {
  9. /// <summary>
  10. /// Represents a sorted async-enumerable sequence.
  11. /// </summary>
  12. /// <typeparam name="TElement">The type of the elements of the sequence.</typeparam>
  13. public interface IOrderedAsyncEnumerable<out TElement> : IAsyncEnumerable<TElement>
  14. {
  15. /// <summary>
  16. /// Performs a subsequent ordering on the elements of an ordered async-enumerable according to a key.
  17. /// </summary>
  18. /// <typeparam name="TKey">The type of the key produced by keySelector.</typeparam>
  19. /// <param name="keySelector">The function used to extract the key for each element.</param>
  20. /// <param name="comparer">The comparer used to compare keys for placement in the returned sequence.</param>
  21. /// <param name="descending">true to sort the elements in descending order; false to sort the elements in ascending order.</param>
  22. /// <returns>An ordered async-enumerable whose elements are sorted according to a key.</returns>
  23. IOrderedAsyncEnumerable<TElement> CreateOrderedEnumerable<TKey>(Func<TElement, TKey> keySelector, IComparer<TKey>? comparer, bool descending);
  24. /// <summary>
  25. /// Performs a subsequent ordering on the elements of an ordered async-enumerable according to a key provided via a ValueTask.
  26. /// </summary>
  27. /// <typeparam name="TKey">The type of the key produced by keySelector.</typeparam>
  28. /// <param name="keySelector">The function used to extract the key for each element as a ValueTask.</param>
  29. /// <param name="comparer">The comparer used to compare keys for placement in the returned sequence.</param>
  30. /// <param name="descending">true to sort the elements in descending order; false to sort the elements in ascending order.</param>
  31. /// <returns>An ordered async-enumerable whose elements are sorted according to a key.</returns>
  32. IOrderedAsyncEnumerable<TElement> CreateOrderedEnumerable<TKey>(Func<TElement, ValueTask<TKey>> keySelector, IComparer<TKey>? comparer, bool descending);
  33. #if !NO_DEEP_CANCELLATION
  34. /// <summary>
  35. /// Performs a subsequent ordering on the elements of an ordered async-enumerable according to a key provided via a ValueTask.
  36. /// </summary>
  37. /// <typeparam name="TKey">The type of the key produced by keySelector.</typeparam>
  38. /// <param name="keySelector">The function used to extract the key for each element as a ValueTask supporting cancellation.</param>
  39. /// <param name="comparer">The comparer used to compare keys for placement in the returned sequence.</param>
  40. /// <param name="descending">true to sort the elements in descending order; false to sort the elements in ascending order.</param>
  41. /// <returns>An ordered async-enumerable whose elements are sorted according to a key.</returns>
  42. IOrderedAsyncEnumerable<TElement> CreateOrderedEnumerable<TKey>(Func<TElement, CancellationToken, ValueTask<TKey>> keySelector, IComparer<TKey>? comparer, bool descending);
  43. #endif
  44. }
  45. }