IAsyncPartition.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Threading.Tasks;
  5. namespace System.Linq
  6. {
  7. /// <summary>
  8. /// An iterator that supports random access and can produce a partial sequence of its items through an optimized path.
  9. /// </summary>
  10. internal interface IAsyncPartition<TElement> : IAsyncIListProvider<TElement>
  11. {
  12. /// <summary>
  13. /// Creates a new partition that skips the specified number of elements from this sequence.
  14. /// </summary>
  15. /// <param name="count">The number of elements to skip.</param>
  16. /// <returns>An <see cref="IPartition{TElement}"/> with the first <paramref name="count"/> items removed.</returns>
  17. IAsyncPartition<TElement> Skip(int count);
  18. /// <summary>
  19. /// Creates a new partition that takes the specified number of elements from this sequence.
  20. /// </summary>
  21. /// <param name="count">The number of elements to take.</param>
  22. /// <returns>An <see cref="IPartition{TElement}"/> with only the first <paramref name="count"/> items.</returns>
  23. IAsyncPartition<TElement> Take(int count);
  24. /// <summary>
  25. /// Gets the item associated with a 0-based index in this sequence.
  26. /// </summary>
  27. /// <param name="index">The 0-based index to access.</param>
  28. /// <returns>The element if found, otherwise, the default value of <see cref="TElement"/>.</returns>
  29. Task<Maybe<TElement>> TryGetElementAsync(int index);
  30. /// <summary>
  31. /// Gets the first item in this sequence.
  32. /// </summary>
  33. /// <returns>The element if found, otherwise, the default value of <see cref="TElement"/>.</returns>
  34. Task<Maybe<TElement>> TryGetFirstAsync();
  35. /// <summary>
  36. /// Gets the last item in this sequence.
  37. /// </summary>
  38. /// <returns>The element if found, otherwise, the default value of <see cref="TElement"/>.</returns>
  39. Task<Maybe<TElement>> TryGetLastAsync();
  40. }
  41. }