IIListProvider.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. namespace System.Linq
  7. {
  8. /// <summary>
  9. /// An iterator that can produce an array or <see cref="List{TElement}"/> through an optimized path.
  10. /// </summary>
  11. interface IIListProvider<TElement> : IAsyncEnumerable<TElement>
  12. {
  13. /// <summary>
  14. /// Produce an array of the sequence through an optimized path.
  15. /// </summary>
  16. /// <param name="cancellationToken"></param>
  17. /// <returns>The array.</returns>
  18. Task<TElement[]> ToArrayAsync(CancellationToken cancellationToken);
  19. /// <summary>
  20. /// Produce a <see cref="List{TElement}"/> of the sequence through an optimized path.
  21. /// </summary>
  22. /// <param name="cancellationToken"></param>
  23. /// <returns>The <see cref="List{TElement}"/>.</returns>
  24. Task<List<TElement>> ToListAsync(CancellationToken cancellationToken);
  25. /// <summary>
  26. /// Returns the count of elements in the sequence.
  27. /// </summary>
  28. /// <param name="onlyIfCheap">If true then the count should only be calculated if doing
  29. /// so is quick (sure or likely to be constant time), otherwise -1 should be returned.</param>
  30. /// <param name="cancellationToken"></param>
  31. /// <returns>The number of elements.</returns>
  32. Task<int> GetCountAsync(bool onlyIfCheap, CancellationToken cancellationToken);
  33. }
  34. }