diff --git a/Base.Tests/Extensions/EnumerableExtensionTests.cs b/Base.Tests/Extensions/EnumerableExtensionTests.cs new file mode 100644 index 0000000..1249f6f --- /dev/null +++ b/Base.Tests/Extensions/EnumerableExtensionTests.cs @@ -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(); +} \ No newline at end of file diff --git a/Base/Base.csproj b/Base/Base.csproj index 55cd423..b18def3 100644 --- a/Base/Base.csproj +++ b/Base/Base.csproj @@ -11,7 +11,7 @@ FruityFoundation.Base https://github.com/kyleratti/FruityFoundation - 1.1.0 + 1.1.1 diff --git a/Base/Extensions/EnumerableExtensions.cs b/Base/Extensions/EnumerableExtensions.cs new file mode 100644 index 0000000..5a2de5c --- /dev/null +++ b/Base/Extensions/EnumerableExtensions.cs @@ -0,0 +1,7 @@ +namespace FruityFoundation.Base.Extensions; + +public static class EnumerableExtensions +{ + public static IEnumerable ConditionalConcat(this IEnumerable enumerable, bool isConditionValid, IEnumerable second) => + !isConditionValid ? enumerable : enumerable.Concat(second); +} \ No newline at end of file