Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions ShittyLINQ/Prepend.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace ShittyLINQ
{
using System;
using System.Collections.Generic;

public static partial class Extensions
{
public static IEnumerable<T> Prepend<T>(this IEnumerable<T> source, T element)
{
if (source == null)
throw new ArgumentNullException(nameof(source));

yield return element;

foreach (var item in source)
{
yield return item;
}
}
}
}
32 changes: 32 additions & 0 deletions ShittyLinqTests/PrependTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}