IAsyncPartition.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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.Threading;
  5. using System.Threading.Tasks;
  6. namespace System.Linq
  7. {
  8. /// <summary>
  9. /// An iterator that supports random access and can produce a partial sequence of its items through an optimized path.
  10. /// </summary>
  11. internal interface IAsyncPartition<TElement> : IAsyncIListProvider<TElement>
  12. {
  13. /// <summary>
  14. /// Creates a new partition that skips the specified number of elements from this sequence.
  15. /// </summary>
  16. /// <param name="count">The number of elements to skip.</param>
  17. /// <returns>An <see cref="IAsyncPartition{TElement}"/> with the first <paramref name="count"/> items removed.</returns>
  18. IAsyncPartition<TElement> Skip(int count);
  19. /// <summary>
  20. /// Creates a new partition that takes the specified number of elements from this sequence.
  21. /// </summary>
  22. /// <param name="count">The number of elements to take.</param>
  23. /// <returns>An <see cref="IAsyncPartition{TElement}"/> with only the first <paramref name="count"/> items.</returns>
  24. IAsyncPartition<TElement> Take(int count);
  25. /// <summary>
  26. /// Gets the item associated with a 0-based index in this sequence.
  27. /// </summary>
  28. /// <param name="index">The 0-based index to access.</param>
  29. /// <param name="cancellationToken">Token to observe for cancellation requests.</param>
  30. /// <returns>The element if found, otherwise, the default value of <see cref="Maybe{TElement}"/>.</returns>
  31. ValueTask<Maybe<TElement>> TryGetElementAtAsync(int index, CancellationToken cancellationToken);
  32. /// <summary>
  33. /// Gets the first item in this sequence.
  34. /// </summary>
  35. /// <param name="cancellationToken">Token to observe for cancellation requests.</param>
  36. /// <returns>The element if found, otherwise, the default value of <see cref="Maybe{TElement}"/>.</returns>
  37. ValueTask<Maybe<TElement>> TryGetFirstAsync(CancellationToken cancellationToken);
  38. /// <summary>
  39. /// Gets the last item in this sequence.
  40. /// </summary>
  41. /// <param name="cancellationToken">Token to observe for cancellation requests.</param>
  42. /// <returns>The element if found, otherwise, the default value of <see cref="Maybe{TElement}"/>.</returns>
  43. ValueTask<Maybe<TElement>> TryGetLastAsync(CancellationToken cancellationToken);
  44. }
  45. }