feat: add IEnumerable<T>.Choose()

This commit is contained in:
Kyle Ratti 2022-12-23 12:34:30 -05:00
parent 3aab47e9c6
commit a045c76140
No known key found for this signature in database
GPG Key ID: 4D429B6287C68DD9

View File

@ -11,4 +11,10 @@ public static class EnumerableExtensions
public static IEnumerable<T> ConditionalWhere<T>(this IEnumerable<T> enumerable, bool isConditionValid, Func<T, bool> pred) =>
!isConditionValid ? enumerable : enumerable.Where(pred);
public static IEnumerable<TOutput> Choose<TInput, TOutput>(this IEnumerable<TInput> enumerable, Func<TInput, TOutput?> mapper) =>
enumerable
.Select(mapper)
.Where(x => x is not null)
.Cast<TOutput>();
}