Last active
August 25, 2025 11:14
-
-
Save einarwh/c0ca5b262b1ee85aca5b7f3a42a7c041 to your computer and use it in GitHub Desktop.
SelectNotNull
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Ext | |
{ | |
public static IEnumerable<TR> SelectNotNull<T, TR>(this IEnumerable<T> source, Func<T, TR?> fn) where TR : struct | |
{ | |
return source.Select(fn).Where(it => it != null).Cast<TR>(); | |
} | |
public static IEnumerable<TR> SelectNotNull<T, TR>(this IEnumerable<T> source, Func<T, TR?> fn) where TR : class | |
{ | |
return source.Select(fn).Where(it => it != null).Cast<TR>(); | |
} | |
public static IEnumerable<TR> SelectNotNullNope<T, TR>(this IEnumerable<T> source, Func<T, TR?> fn) | |
{ | |
return source.Select(fn).Where(it => it != null).Cast<TR>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment