feat: add IEnumerable<T>.Choose()
This commit is contained in:
parent
3aab47e9c6
commit
a045c76140
|
@ -11,4 +11,10 @@ public static class EnumerableExtensions
|
||||||
|
|
||||||
public static IEnumerable<T> ConditionalWhere<T>(this IEnumerable<T> enumerable, bool isConditionValid, Func<T, bool> pred) =>
|
public static IEnumerable<T> ConditionalWhere<T>(this IEnumerable<T> enumerable, bool isConditionValid, Func<T, bool> pred) =>
|
||||||
!isConditionValid ? enumerable : enumerable.Where(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>();
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user