// 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 IOrderedAsyncEnumerable OrderBy(this IAsyncEnumerable source, Func keySelector) => new OrderedAsyncEnumerable(source, keySelector, comparer: null, descending: false, parent: null); public static IOrderedAsyncEnumerable OrderByAwait(this IAsyncEnumerable source, Func> keySelector) => new OrderedAsyncEnumerableWithTask(source, keySelector, comparer: null, descending: false, parent: null); #if !NO_DEEP_CANCELLATION public static IOrderedAsyncEnumerable OrderByAwaitWithCancellation(this IAsyncEnumerable source, Func> keySelector) => new OrderedAsyncEnumerableWithTaskAndCancellation(source, keySelector, comparer: null, descending: false, parent: null); #endif public static IOrderedAsyncEnumerable OrderBy(this IAsyncEnumerable source, Func keySelector, IComparer comparer) => new OrderedAsyncEnumerable(source, keySelector, comparer, descending: false, parent: null); public static IOrderedAsyncEnumerable OrderByAwait(this IAsyncEnumerable source, Func> keySelector, IComparer comparer) => new OrderedAsyncEnumerableWithTask(source, keySelector, comparer, descending: false, parent: null); #if !NO_DEEP_CANCELLATION public static IOrderedAsyncEnumerable OrderByAwaitWithCancellation(this IAsyncEnumerable source, Func> keySelector, IComparer comparer) => new OrderedAsyncEnumerableWithTaskAndCancellation(source, keySelector, comparer, descending: false, parent: null); #endif public static IOrderedAsyncEnumerable OrderByDescending(this IAsyncEnumerable source, Func keySelector) => new OrderedAsyncEnumerable(source, keySelector, comparer: null, descending: true, parent: null); public static IOrderedAsyncEnumerable OrderByDescendingAwait(this IAsyncEnumerable source, Func> keySelector) => new OrderedAsyncEnumerableWithTask(source, keySelector, comparer: null, descending: true, parent: null); #if !NO_DEEP_CANCELLATION public static IOrderedAsyncEnumerable OrderByDescendingAwaitWithCancellation(this IAsyncEnumerable source, Func> keySelector) => new OrderedAsyncEnumerableWithTaskAndCancellation(source, keySelector, comparer: null, descending: true, parent: null); #endif public static IOrderedAsyncEnumerable OrderByDescending(this IAsyncEnumerable source, Func keySelector, IComparer comparer) => new OrderedAsyncEnumerable(source, keySelector, comparer, descending: true, parent: null); public static IOrderedAsyncEnumerable OrderByDescendingAwait(this IAsyncEnumerable source, Func> keySelector, IComparer comparer) => new OrderedAsyncEnumerableWithTask(source, keySelector, comparer, descending: true, parent: null); #if !NO_DEEP_CANCELLATION public static IOrderedAsyncEnumerable OrderByDescendingAwaitWithCancellation(this IAsyncEnumerable source, Func> keySelector, IComparer comparer) => new OrderedAsyncEnumerableWithTaskAndCancellation(source, keySelector, comparer, descending: true, parent: null); #endif public static IOrderedAsyncEnumerable ThenBy(this IOrderedAsyncEnumerable source, Func keySelector) { if (source == null) throw Error.ArgumentNull(nameof(source)); return source.CreateOrderedEnumerable(keySelector, comparer: null, descending: false); } public static IOrderedAsyncEnumerable ThenByAwait(this IOrderedAsyncEnumerable source, Func> keySelector) { if (source == null) throw Error.ArgumentNull(nameof(source)); return source.CreateOrderedEnumerable(keySelector, comparer: default(IComparer), descending: false); } #if !NO_DEEP_CANCELLATION public static IOrderedAsyncEnumerable ThenByAwaitWithCancellation(this IOrderedAsyncEnumerable source, Func> keySelector) { if (source == null) throw Error.ArgumentNull(nameof(source)); return source.CreateOrderedEnumerable(keySelector, comparer: null, descending: false); } #endif public static IOrderedAsyncEnumerable ThenBy(this IOrderedAsyncEnumerable source, Func keySelector, IComparer comparer) { if (source == null) throw Error.ArgumentNull(nameof(source)); return source.CreateOrderedEnumerable(keySelector, comparer, descending: false); } public static IOrderedAsyncEnumerable ThenByAwait(this IOrderedAsyncEnumerable source, Func> keySelector, IComparer comparer) { if (source == null) throw Error.ArgumentNull(nameof(source)); return source.CreateOrderedEnumerable(keySelector, comparer, descending: false); } #if !NO_DEEP_CANCELLATION public static IOrderedAsyncEnumerable ThenByAwaitWithCancellation(this IOrderedAsyncEnumerable source, Func> keySelector, IComparer comparer) { if (source == null) throw Error.ArgumentNull(nameof(source)); return source.CreateOrderedEnumerable(keySelector, comparer, descending: false); } #endif public static IOrderedAsyncEnumerable ThenByDescending(this IOrderedAsyncEnumerable source, Func keySelector) { if (source == null) throw Error.ArgumentNull(nameof(source)); return source.CreateOrderedEnumerable(keySelector, comparer: null, descending: true); } public static IOrderedAsyncEnumerable ThenByDescendingAwait(this IOrderedAsyncEnumerable source, Func> keySelector) { if (source == null) throw Error.ArgumentNull(nameof(source)); return source.CreateOrderedEnumerable(keySelector, comparer: default(IComparer), descending: true); } #if !NO_DEEP_CANCELLATION public static IOrderedAsyncEnumerable ThenByDescendingAwaitWithCancellation(this IOrderedAsyncEnumerable source, Func> keySelector) { if (source == null) throw Error.ArgumentNull(nameof(source)); return source.CreateOrderedEnumerable(keySelector, comparer: null, descending: true); } #endif public static IOrderedAsyncEnumerable ThenByDescending(this IOrderedAsyncEnumerable source, Func keySelector, IComparer comparer) { if (source == null) throw Error.ArgumentNull(nameof(source)); return source.CreateOrderedEnumerable(keySelector, comparer, descending: true); } public static IOrderedAsyncEnumerable ThenByDescendingAwait(this IOrderedAsyncEnumerable source, Func> keySelector, IComparer comparer) { if (source == null) throw Error.ArgumentNull(nameof(source)); return source.CreateOrderedEnumerable(keySelector, comparer, descending: true); } #if !NO_DEEP_CANCELLATION public static IOrderedAsyncEnumerable ThenByDescendingAwaitWithCancellation(this IOrderedAsyncEnumerable source, Func> keySelector, IComparer comparer) { if (source == null) throw Error.ArgumentNull(nameof(source)); return source.CreateOrderedEnumerable(keySelector, comparer, descending: true); } #endif } }