using System; using System.Collections.Generic; using System.Linq; namespace FruityFoundation.Base.Extensions; 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) where TInput : class? => enumerable .Select(mapper) .Where(x => x is not null) .Cast(); public static IEnumerable Choose(this IEnumerable enumerable, Func mapper) where TOutput : struct => enumerable .Select(mapper) .Where(x => x.HasValue) .Select(x => x!.Value); }