1
0

Skip.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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.Collections.Generic;
  5. namespace System.Linq
  6. {
  7. public static partial class AsyncEnumerable
  8. {
  9. public static IAsyncEnumerable<TSource> Skip<TSource>(this IAsyncEnumerable<TSource> source, int count)
  10. {
  11. if (source == null)
  12. throw new ArgumentNullException(nameof(source));
  13. if (count <= 0)
  14. {
  15. // Return source if not actually skipping, but only if it's a type from here, to avoid
  16. // issues if collections are used as keys or otherwise must not be aliased.
  17. if (source is AsyncIterator<TSource> || source is IAsyncPartition<TSource>)
  18. {
  19. return source;
  20. }
  21. count = 0;
  22. }
  23. else if (source is IAsyncPartition<TSource> partition)
  24. {
  25. return partition.Skip(count);
  26. }
  27. else if (source is IList<TSource> list)
  28. {
  29. return new AsyncListPartition<TSource>(list, count, int.MaxValue);
  30. }
  31. return new AsyncEnumerablePartition<TSource>(source, count, -1);
  32. }
  33. }
  34. }