/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ using System; using System.Collections.Generic; using System.Linq; namespace Microsoft.Rest.ClientRuntime.PowerShell { internal static class CollectionExtensions { public static T[] NullIfEmpty(this T[] collection) => (collection?.Any() ?? false) ? collection : null; public static IEnumerable EmptyIfNull(this IEnumerable collection) => collection ?? Enumerable.Empty(); // https://stackoverflow.com/a/4158364/294804 public static IEnumerable DistinctBy(this IEnumerable collection, Func selector) => collection.GroupBy(selector).Select(group => group.First()); } }