Browse Source

Added an additional helper extension

pull/44/head
Anairkoen Schno 4 years ago
parent
commit
084706c3d8
1 changed files with 13 additions and 3 deletions
  1. +13
    -3
      IPA.Loader/Utilities/EnumerableExtensions.cs

+ 13
- 3
IPA.Loader/Utilities/EnumerableExtensions.cs View File

@ -165,7 +165,7 @@ namespace IPA.Utilities
} }
/// <summary> /// <summary>
/// LINQ extension method that filters <see langword="null"/> elements out of an enumeration.
/// LINQ-style extension method that filters <see langword="null"/> elements out of an enumeration.
/// </summary> /// </summary>
/// <typeparam name="T">the type of the enumeration</typeparam> /// <typeparam name="T">the type of the enumeration</typeparam>
/// <param name="self">the enumeration to filter</param> /// <param name="self">the enumeration to filter</param>
@ -174,7 +174,7 @@ namespace IPA.Utilities
=> self.Where(o => o != null); => self.Where(o => o != null);
/// <summary> /// <summary>
/// LINQ extension method that filters <see langword="null"/> elements out of an enumeration based on a converter.
/// LINQ-style extension method that filters <see langword="null"/> elements out of an enumeration based on a converter.
/// </summary> /// </summary>
/// <typeparam name="T">the type of the enumeration</typeparam> /// <typeparam name="T">the type of the enumeration</typeparam>
/// <typeparam name="U">the type to compare to null</typeparam> /// <typeparam name="U">the type to compare to null</typeparam>
@ -185,7 +185,7 @@ namespace IPA.Utilities
=> self.Where(o => pred(o) != null); => self.Where(o => pred(o) != null);
/// <summary> /// <summary>
/// LINQ extension method that filters <see langword="null"/> elements from an enumeration of nullable types.
/// LINQ-style extension method that filters <see langword="null"/> elements from an enumeration of nullable types.
/// </summary> /// </summary>
/// <typeparam name="T">the underlying type of the nullable enumeration</typeparam> /// <typeparam name="T">the underlying type of the nullable enumeration</typeparam>
/// <param name="self">the enumeration to filter</param> /// <param name="self">the enumeration to filter</param>
@ -193,5 +193,15 @@ namespace IPA.Utilities
public static IEnumerable<T> NonNull<T>(this IEnumerable<T?> self) where T : struct public static IEnumerable<T> NonNull<T>(this IEnumerable<T?> self) where T : struct
=> self.Where(o => o != null).Select(o => o.Value); => self.Where(o => o != null).Select(o => o.Value);
/// <summary>
/// LINQ-style extension method that filters <see langword="null"/> elements out of an enumeration based on a converter to a nullable type.
/// </summary>
/// <typeparam name="T">the type of the enumeration</typeparam>
/// <typeparam name="U">the type of the predicate's resulting nullable</typeparam>
/// <param name="self">the enumeration to filter</param>
/// <param name="pred">the predicate to select for filtering</param>
/// <returns>a filtered enumerable</returns>
public static IEnumerable<T> NonNull<T, U>(this IEnumerable<T> self, Func<T, U?> pred) where U : struct
=> self.Where(o => pred(o) != null);
} }
} }

Loading…
Cancel
Save