// 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; internal sealed class EmptyAsyncIterator : IAsyncPartition, IAsyncEnumerator { public static readonly EmptyAsyncIterator Instance = new EmptyAsyncIterator(); public TValue Current => default; 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( #if NO_ARRAY_EMPTY EmptyArray.Value #else Array.Empty() #endif ); public Task> ToListAsync(CancellationToken cancellationToken) => Task.FromResult(new List()); public Task> TryGetElementAsync(int index, CancellationToken cancellationToken) => Task.FromResult(new Maybe()); public Task> TryGetFirstAsync(CancellationToken cancellationToken) => Task.FromResult(new Maybe()); public Task> TryGetLastAsync(CancellationToken cancellationToken) => Task.FromResult(new Maybe()); public ValueTask MoveNextAsync() => new ValueTask(false); public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken) => this; public ValueTask DisposeAsync() => default; } } }