/// <summary> /// Prepends a single value to a sequence. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam> /// <param name="source">The sequence to prepend to.</param> /// <param name="value">The value to prepend.</param> /// <returns> /// Returns a sequence where a value is prepended to it. /// </returns> /// <remarks> /// This operator uses deferred execution and streams its results. /// </remarks> /// <code> /// int[] numbers = { 1, 2, 3 }; /// IEnumerable<int> result = numbers.Prepend(0); /// </code> /// The /// <c>result</c> /// variable, when iterated over, will yield /// 0, 1, 2 and 3, in turn. public static IEnumerable <TSource> Prepend <TSource>(this IEnumerable <TSource> source, TSource value) { if (source == null) { throw new ArgumentNullException("source"); } return(LinqEnumerable.Repeat(value, 1).Concat(source)); }
/// <summary> /// Returns a sequence consisting of the head elements and the given tail element. /// </summary> /// <typeparam name="T">Type of sequence</typeparam> /// <param name="head">All elements of the head. Must not be null.</param> /// <param name="tail">Tail element of the new sequence.</param> /// <returns>A sequence consisting of the head elements and the given tail element.</returns> /// <remarks>This operator uses deferred execution and streams its results.</remarks> public static IEnumerable <T> Concat <T>(this IEnumerable <T> head, T tail) { if (head == null) { throw new ArgumentNullException("head"); } return(head.Concat(LinqEnumerable.Repeat(tail, 1))); }
public void YieldTests() { int i = 1; Assert.True(LinqEnumerable.Yield(i).SequenceEqual(new[] { 1 })); }
public void Repeat() { Assert.True(LinqEnumerable.Repeat(1u, 3u).SequenceEqual(new[] { 1u, 1u, 1u })); }
public void RangeUshort() { Assert.True(LinqEnumerable.RangeUshort(5).SequenceEqual(new ushort[] { 0, 1, 2, 3, 4 })); }
public void Yield_Prepend_Append() { Assert.True(LinqEnumerable.Yield(3).Prepend(2).Append(4).SequenceEqual(new[] { 2, 3, 4 })); }