feat: add Enumerable.ConditionalConcat
This commit is contained in:
parent
e12137b302
commit
ea050f098a
13
Base.Tests/Extensions/EnumerableExtensionTests.cs
Normal file
13
Base.Tests/Extensions/EnumerableExtensionTests.cs
Normal 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();
|
||||||
|
}
|
|
@ -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>
|
||||||
|
|
7
Base/Extensions/EnumerableExtensions.cs
Normal file
7
Base/Extensions/EnumerableExtensions.cs
Normal 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);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user