@Bogdanp maybe this is another way to express it:
public static class EnumerableExtensions
{
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)
.OfType<T>();
}
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)
.Select(item => item.Value);
}
}