diff --git a/ShittyLINQ/Prepend.cs b/ShittyLINQ/Prepend.cs new file mode 100644 index 0000000..9d14c4b --- /dev/null +++ b/ShittyLINQ/Prepend.cs @@ -0,0 +1,21 @@ +namespace ShittyLINQ +{ + using System; + using System.Collections.Generic; + + public static partial class Extensions + { + public static IEnumerable Prepend(this IEnumerable source, T element) + { + if (source == null) + throw new ArgumentNullException(nameof(source)); + + yield return element; + + foreach (var item in source) + { + yield return item; + } + } + } +} \ No newline at end of file diff --git a/ShittyLinqTests/PrependTests.cs b/ShittyLinqTests/PrependTests.cs new file mode 100644 index 0000000..d52942d --- /dev/null +++ b/ShittyLinqTests/PrependTests.cs @@ -0,0 +1,32 @@ +namespace ShittyTests +{ + using Microsoft.VisualStudio.TestTools.UnitTesting; + using ShittyLINQ; + using ShittyTests.TestHelpers; + + [TestClass] + public class PrependTests + { + [TestMethod] + public void Prepend_ReturnsExpected() + { + var source = new[] { 1, 2, 3, 4, 5 }; + var expectedResult = new[] { 0, 1, 2, 3, 4, 5 }; + + var result = source.Prepend(0); + + TestHelper.AssertCollectionsAreSame(expectedResult, result); + } + + [TestMethod] + public void Prepend_ReturnsExpectedWithEmptyCollection() + { + var source = new int[] { }; + var expectedResult = new int[] { 0 }; + + var result = source.Prepend(0); + + TestHelper.AssertCollectionsAreSame(expectedResult, result); + } + } +} \ No newline at end of file