Empty.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. using System.Threading;
  6. using System.Threading.Tasks;
  7. namespace System.Linq
  8. {
  9. public static partial class AsyncEnumerable
  10. {
  11. public static IAsyncEnumerable<TValue> Empty<TValue>()
  12. {
  13. return new EmptyAsyncIterator<TValue>();
  14. }
  15. private sealed class EmptyAsyncIterator<TValue> : AsyncIterator<TValue>, IAsyncPartition<TValue>
  16. {
  17. public override AsyncIterator<TValue> Clone() => new EmptyAsyncIterator<TValue>();
  18. public Task<int> GetCountAsync(bool onlyIfCheap, CancellationToken cancellationToken) => Task.FromResult(0);
  19. public IAsyncPartition<TValue> Skip(int count) => this;
  20. public IAsyncPartition<TValue> Take(int count) => this;
  21. public Task<TValue[]> ToArrayAsync(CancellationToken cancellationToken) => Task.FromResult(Array.Empty<TValue>());
  22. public Task<List<TValue>> ToListAsync(CancellationToken cancellationToken) => Task.FromResult(new List<TValue>());
  23. public Task<Maybe<TValue>> TryGetElementAt(int index) => Task.FromResult(new Maybe<TValue>());
  24. public Task<Maybe<TValue>> TryGetFirst() => Task.FromResult(new Maybe<TValue>());
  25. public Task<Maybe<TValue>> TryGetLast() => Task.FromResult(new Maybe<TValue>());
  26. protected override Task<bool> MoveNextCore() => TaskExt.False;
  27. }
  28. }
  29. }