From a045c76140d8e0b369ec6edc18548226e61a38af Mon Sep 17 00:00:00 2001 From: Kyle Ratti Date: Fri, 23 Dec 2022 12:34:30 -0500 Subject: [PATCH] feat: add IEnumerable.Choose() --- Base/Extensions/EnumerableExtensions.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Base/Extensions/EnumerableExtensions.cs b/Base/Extensions/EnumerableExtensions.cs index b1da234..ef0eede 100644 --- a/Base/Extensions/EnumerableExtensions.cs +++ b/Base/Extensions/EnumerableExtensions.cs @@ -8,7 +8,13 @@ public static class EnumerableExtensions { public static IEnumerable ConditionalConcat(this IEnumerable enumerable, bool isConditionValid, IEnumerable second) => !isConditionValid ? enumerable : enumerable.Concat(second); - + public static IEnumerable ConditionalWhere(this IEnumerable enumerable, bool isConditionValid, Func pred) => !isConditionValid ? enumerable : enumerable.Where(pred); + + public static IEnumerable Choose(this IEnumerable enumerable, Func mapper) => + enumerable + .Select(mapper) + .Where(x => x is not null) + .Cast(); } \ No newline at end of file