feat: add Enumerable.ConditionalConcat

This commit is contained in:
Kyle Ratti 2022-09-23 21:07:42 -04:00
parent e12137b302
commit ea050f098a
No known key found for this signature in database
GPG Key ID: 321BA8EB09CD93F4
3 changed files with 21 additions and 1 deletions

View File

@ -0,0 +1,13 @@
using System.Linq;
using FruityFoundation.Base.Extensions;
using NUnit.Framework;
namespace Base.Tests.Extensions;
public class EnumerableExtensionTests
{
[TestCase(new object[] { 0, 1, 2 }, true, new object[] { 85 }, ExpectedResult = new object[] { 0, 1, 2, 85 })]
[TestCase(new object[] { "hi" }, false, new object[] { "there" }, ExpectedResult = new object[] { "hi" })]
public object[] TestConditionalConcat(object[] input, bool isConditionValid, object[] second) =>
input.ConditionalConcat(isConditionValid, second).ToArray();
}

View File

@ -11,7 +11,7 @@
<Company /> <Company />
<Product>FruityFoundation.Base</Product> <Product>FruityFoundation.Base</Product>
<RepositoryUrl>https://github.com/kyleratti/FruityFoundation</RepositoryUrl> <RepositoryUrl>https://github.com/kyleratti/FruityFoundation</RepositoryUrl>
<PackageVersion>1.1.0</PackageVersion> <PackageVersion>1.1.1</PackageVersion>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@ -0,0 +1,7 @@
namespace FruityFoundation.Base.Extensions;
public static class EnumerableExtensions
{
public static IEnumerable<T> ConditionalConcat<T>(this IEnumerable<T> enumerable, bool isConditionValid, IEnumerable<T> second) =>
!isConditionValid ? enumerable : enumerable.Concat(second);
}