using System; using System.Collections.Generic; using System.Linq; namespace FruityFoundation.Base.Structures; public static class EnumerableExtensions { public static IEnumerable ConditionalConcat(this IEnumerable enumerable, bool condition, IEnumerable second) => !condition ? enumerable : enumerable.Concat(second); public static IEnumerable ConditionalAppend(this IEnumerable enumerable, bool condition, T second) => condition ? enumerable.Append(second) : enumerable; public static IEnumerable ConditionalWhere(this IEnumerable enumerable, bool condition, Func pred) => !condition ? enumerable : enumerable.Where(pred); public static IEnumerable Choose(this IEnumerable enumerable, Func> chooser) => enumerable.Select(chooser).Where(x => x.HasValue).Select(x => x.Value); }