|
|
@ -165,7 +165,7 @@ namespace IPA.Utilities |
|
|
|
} |
|
|
|
|
|
|
|
/// <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>
|
|
|
|
/// <typeparam name="T">the type of the enumeration</typeparam>
|
|
|
|
/// <param name="self">the enumeration to filter</param>
|
|
|
@ -174,7 +174,7 @@ namespace IPA.Utilities |
|
|
|
=> self.Where(o => o != null); |
|
|
|
|
|
|
|
/// <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>
|
|
|
|
/// <typeparam name="T">the type of the enumeration</typeparam>
|
|
|
|
/// <typeparam name="U">the type to compare to null</typeparam>
|
|
|
@ -185,7 +185,7 @@ namespace IPA.Utilities |
|
|
|
=> self.Where(o => pred(o) != null); |
|
|
|
|
|
|
|
/// <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>
|
|
|
|
/// <typeparam name="T">the underlying type of the nullable enumeration</typeparam>
|
|
|
|
/// <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 |
|
|
|
=> 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); |
|
|
|
} |
|
|
|
} |