diff --git a/Source/Cogworks.Essentials/Extensions/EnumerableExtensions.cs b/Source/Cogworks.Essentials/Extensions/EnumerableExtensions.cs index 761222b..fc5b298 100644 --- a/Source/Cogworks.Essentials/Extensions/EnumerableExtensions.cs +++ b/Source/Cogworks.Essentials/Extensions/EnumerableExtensions.cs @@ -14,8 +14,11 @@ public static bool HasAny(this IEnumerable items) public static bool HasAny(this IEnumerable items) => items != null && items.GetEnumerator().MoveNext(); - public static TOutput FirstOrDefaultOfType(this IEnumerable publishedContents) - => publishedContents.OfType().FirstOrDefault(); + public static TOutput FirstOrDefaultOfType(this IEnumerable items) + => items.OfType().FirstOrDefault(); + + public static TOutput FirstOrDefaultOfType(this IEnumerable items) + => items.OfType().FirstOrDefault(); public static string JoinIfNotNull(this IEnumerable items, Func func, string separator = Separators.Space) @@ -23,6 +26,19 @@ public static string JoinIfNotNull(this IEnumerable ite ? string.Join(separator, items.Select(func)) : string.Empty; + public static IEnumerable IntersectManyWithHash(this IEnumerable> values) + => !values.Any() + ? Enumerable.Empty() + : values + .Skip(1) + .Aggregate( + new HashSet(values.First()), + (h, e) => + { + h.IntersectWith(e); + return h; + }); + public static IEnumerable<(T item, int index)> WithIndex(this IEnumerable items) => items.HasAny() ? items