ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

Follow

Follows sequence with new element

Source

/// <summary>
/// Follows sequence with new element
/// </summary>
/// <typeparam name="TSource">Source sequence element type</typeparam>
/// <param name="sequence">Source sequence</param>
/// <param name="value">New element value</param>
/// <returns>Sequence with new last element</returns>
public static IEnumerable<TSource> Follow<TSource>(this IEnumerable<TSource> sequence, TSource value)
{
    foreach (var item in sequence)
    {
        yield return item;
    }

    yield return value;
}
{
    var i = 0;

    while (true)
    {
        yield return @this.AddMonths(++i * step);
    }
    // ReSharper disable once FunctionNeverReturns
}

Example

var list = new List<int> {1, 2, 3};

list.Follow(4);

Author: Nikoloz Pachuashvili

Submitted on: 18 dec. 2015

Language: C#

Type: IEnumerable<T>

Views: 3921