// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; namespace System.Linq { public static partial class AsyncEnumerable { public static IAsyncEnumerable Empty() => EmptyAsyncIterator.Instance; private sealed class EmptyAsyncIterator : IAsyncPartition, IAsyncEnumerator { public static readonly EmptyAsyncIterator Instance = new EmptyAsyncIterator(); public TValue Current => default(TValue); public Task GetCountAsync(bool onlyIfCheap, CancellationToken cancellationToken) => Task.FromResult(0); public IAsyncPartition Skip(int count) => this; public IAsyncPartition Take(int count) => this; public Task ToArrayAsync(CancellationToken cancellationToken) => Task.FromResult(Array.Empty()); public Task> ToListAsync(CancellationToken cancellationToken) => Task.FromResult(new List()); public Task> TryGetElementAsync(int index) => Task.FromResult(new Maybe()); public Task> TryGetFirstAsync() => Task.FromResult(new Maybe()); public Task> TryGetLastAsync() => Task.FromResult(new Maybe()); public Task MoveNextAsync() => TaskExt.False; public IAsyncEnumerator GetAsyncEnumerator() => this; public Task DisposeAsync() => TaskExt.CompletedTask; } } }