IIListProvider.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  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. /// <returns>The array.</returns>
  17. Task<TElement[]> ToArrayAsync(CancellationToken cancellationToken);
  18. /// <summary>
  19. /// Produce a <see cref="List{TElement}"/> of the sequence through an optimized path.
  20. /// </summary>
  21. /// <returns>The <see cref="List{TElement}"/>.</returns>
  22. Task<List<TElement>> ToListAsync(CancellationToken cancellationToken);
  23. /// <summary>
  24. /// Returns the count of elements in the sequence.
  25. /// </summary>
  26. /// <param name="onlyIfCheap">If true then the count should only be calculated if doing
  27. /// so is quick (sure or likely to be constant time), otherwise -1 should be returned.</param>
  28. /// <returns>The number of elements.</returns>
  29. Task<int> GetCountAsync(bool onlyIfCheap, CancellationToken cancellationToken);
  30. }
  31. }