Skip to content

Commit

Permalink
Merge pull request #12 from Orace/vto-Lead
Browse files Browse the repository at this point in the history
Lead overload returning tuple (T, T).
  • Loading branch information
atifaziz authored Nov 9, 2019
2 parents c3328fa + 3f4cc26 commit 15e0c1b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
31 changes: 31 additions & 0 deletions MoreLinq/Extensions.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3247,6 +3247,37 @@ public static T LastOrDefault<T>(this IExtremaEnumerable<T> source)
[GeneratedCode("MoreLinq.ExtensionsGenerator", "1.0.0.0")]
public static partial class LeadExtension
{

/// <summary>
/// Produces a sequence of tuple containing a pair of elements separated by a positive offset.
/// </summary>
/// <remarks>
/// This operator evaluates in a deferred and streaming manner.<br/>
/// For elements of the sequence that are less than <paramref name="offset"/> items from the end,
/// default(T) is used as the lead value.<br/>
/// </remarks>
/// <typeparam name="TSource">The type of the elements in the source sequence</typeparam>
/// <param name="source">The sequence over which to evaluate Lead</param>
/// <param name="offset">The offset (expressed as a positive number) by which to lead each element of the sequence</param>
/// <returns>The produced sequence of tuple</returns>

public static IEnumerable<(TSource Item, TSource OffsetItem)> Lead<TSource>(this IEnumerable<TSource> source, int offset)
=> MoreEnumerable.Lead(source, offset);

/// <summary>
/// Produces a sequence of tuple containing a pair of elements separated by a positive offset.
/// </summary>
/// <remarks>
/// This operator evaluates in a deferred and streaming manner.<br/>
/// </remarks>
/// <typeparam name="TSource">The type of the elements in the source sequence</typeparam>
/// <param name="source">The sequence over which to evaluate Lead</param>
/// <param name="offset">The offset (expressed as a positive number) by which to lead each element of the sequence</param>
/// <param name="defaultLeadValue">A default value supplied for the leading element when none is available</param>
/// <returns>The produced sequence of tuple</returns>

public static IEnumerable<(TSource Item, TSource OffsetItem)> Lead<TSource>(this IEnumerable<TSource> source, int offset, TSource defaultLeadValue)
=> MoreEnumerable.Lead(source, offset, defaultLeadValue);
/// <summary>
/// Produces a projection of a sequence by evaluating pairs of elements separated by a positive offset.
/// </summary>
Expand Down
35 changes: 35 additions & 0 deletions MoreLinq/Lead.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,40 @@ public static IEnumerable<TResult> Lead<TSource, TResult>(this IEnumerable<TSour
yield return resultSelector(leadQueue.Dequeue(), defaultLeadValue);
}
}

/// <summary>
/// Produces a sequence of tuple containing a pair of elements separated by a positive offset.
/// </summary>
/// <remarks>
/// This operator evaluates in a deferred and streaming manner.<br/>
/// For elements of the sequence that are less than <paramref name="offset"/> items from the end,
/// default(T) is used as the lead value.<br/>
/// </remarks>
/// <typeparam name="TSource">The type of the elements in the source sequence</typeparam>
/// <param name="source">The sequence over which to evaluate Lead</param>
/// <param name="offset">The offset (expressed as a positive number) by which to lead each element of the sequence</param>
/// <returns>The produced sequence of tuple</returns>

public static IEnumerable<(TSource Item, TSource OffsetItem)> Lead<TSource>(this IEnumerable<TSource> source, int offset)
{
return Lead(source, offset, default, ValueTuple.Create);
}

/// <summary>
/// Produces a sequence of tuple containing a pair of elements separated by a positive offset.
/// </summary>
/// <remarks>
/// This operator evaluates in a deferred and streaming manner.<br/>
/// </remarks>
/// <typeparam name="TSource">The type of the elements in the source sequence</typeparam>
/// <param name="source">The sequence over which to evaluate Lead</param>
/// <param name="offset">The offset (expressed as a positive number) by which to lead each element of the sequence</param>
/// <param name="defaultLeadValue">A default value supplied for the leading element when none is available</param>
/// <returns>The produced sequence of tuple</returns>

public static IEnumerable<(TSource Item, TSource OffsetItem)> Lead<TSource>(this IEnumerable<TSource> source, int offset, TSource defaultLeadValue)
{
return Lead(source, offset, default, ValueTuple.Create);
}
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ This method has 4 overloads.
Produces a projection of a sequence by evaluating pairs of elements separated
by a positive offset.

This method has 2 overloads.
This method has 4 overloads.

### LeftJoin

Expand Down

0 comments on commit 15e0c1b

Please sign in to comment.