using System; using System.Collections.Generic; using System.Linq; namespace NzbDrone.Common.Extensions { public static class EnumerableExtensions { public static IEnumerable DistinctBy(this IEnumerable source, Func keySelector) { var knownKeys = new HashSet(); return source.Where(element => knownKeys.Add(keySelector(element))); } public static void AddIfNotNull(this List source, TSource item) { if (item == null) { return; } source.Add(item); } public static bool Empty(this IEnumerable source) { return !source.Any(); } public static bool None(this IEnumerable source, Func predicate) { return !source.Any(predicate); } public static bool NotAll(this IEnumerable source, Func predicate) { return !source.All(predicate); } public static List SelectList(this IEnumerable source, Func predicate) { return source.Select(predicate).ToList(); } } }