/// <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(nameof(head)); } return(head is PcNode <T> node ? node.Concat(tail) : PcNode <T> .WithSource(head).Concat(tail)); }
/// <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><![CDATA[ /// int[] numbers = { 1, 2, 3 }; /// var 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(nameof(source)); } return(source is PcNode <TSource> node ? node.Prepend(value) : PcNode <TSource> .WithSource(source).Prepend(value)); }
public Item(T item, bool isPrepend, PcNode <T> next) { if (next == null) { throw new ArgumentNullException(nameof(next)); } Value = item; IsPrepend = isPrepend; ConcatCount = next is Item nextItem ? nextItem.ConcatCount + (isPrepend ? 0 : 1) : 1; Next = next; }