From d12739874c5dbda2fa7d458f105fc523932bab46 Mon Sep 17 00:00:00 2001 From: Orace Date: Mon, 4 Nov 2019 08:58:24 +0100 Subject: [PATCH 1/3] sourve enumerator wasn't disposed in Lead implementation. --- MoreLinq/Lead.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MoreLinq/Lead.cs b/MoreLinq/Lead.cs index dc5a9c391..a354aea30 100644 --- a/MoreLinq/Lead.cs +++ b/MoreLinq/Lead.cs @@ -65,7 +65,7 @@ public static IEnumerable Lead(this IEnumerable _() { var leadQueue = new Queue(offset); - var iter = source.GetEnumerator(); + using var iter = source.GetEnumerator(); bool hasMore; // first, prefetch and populate the lead queue with the next step of From 39c4014f3f7fd63e45764d87d5871e2901053988 Mon Sep 17 00:00:00 2001 From: Orace Date: Mon, 4 Nov 2019 09:13:16 +0100 Subject: [PATCH 2/3] Add ValueTuple overload for Lead. --- MoreLinq/Extensions.g.cs | 31 +++++++++++++++++++++++++++++++ MoreLinq/Lead.cs | 35 +++++++++++++++++++++++++++++++++++ README.md | 2 +- 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/MoreLinq/Extensions.g.cs b/MoreLinq/Extensions.g.cs index 06fb99e8e..8c014d937 100644 --- a/MoreLinq/Extensions.g.cs +++ b/MoreLinq/Extensions.g.cs @@ -3192,6 +3192,37 @@ public static T LastOrDefault(this IExtremaEnumerable source) [GeneratedCode("MoreLinq.ExtensionsGenerator", "1.0.0.0")] public static partial class LeadExtension { + + /// + /// Produces a sequence of tuple containing a pair of elements separated by a positive offset. + /// + /// + /// This operator evaluates in a deferred and streaming manner.
+ /// For elements of the sequence that are less than items from the end, + /// default(T) is used as the lead value.
+ ///
+ /// The type of the elements in the source sequence + /// The sequence over which to evaluate Lead + /// The offset (expressed as a positive number) by which to lead each element of the sequence + /// The produced sequence of tuple + + public static IEnumerable<(TSource Item, TSource OffsetItem)> Lead(this IEnumerable source, int offset) + => MoreEnumerable.Lead(source, offset); + + /// + /// Produces a sequence of tuple containing a pair of elements separated by a positive offset. + /// + /// + /// This operator evaluates in a deferred and streaming manner.
+ ///
+ /// The type of the elements in the source sequence + /// The sequence over which to evaluate Lead + /// The offset (expressed as a positive number) by which to lead each element of the sequence + /// A default value supplied for the leading element when none is available + /// The produced sequence of tuple + + public static IEnumerable<(TSource Item, TSource OffsetItem)> Lead(this IEnumerable source, int offset, TSource defaultLeadValue) + => MoreEnumerable.Lead(source, offset, defaultLeadValue); /// /// Produces a projection of a sequence by evaluating pairs of elements separated by a positive offset. /// diff --git a/MoreLinq/Lead.cs b/MoreLinq/Lead.cs index a354aea30..e2095878d 100644 --- a/MoreLinq/Lead.cs +++ b/MoreLinq/Lead.cs @@ -85,5 +85,40 @@ public static IEnumerable Lead(this IEnumerable + /// Produces a sequence of tuple containing a pair of elements separated by a positive offset. + /// + /// + /// This operator evaluates in a deferred and streaming manner.
+ /// For elements of the sequence that are less than items from the end, + /// default(T) is used as the lead value.
+ ///
+ /// The type of the elements in the source sequence + /// The sequence over which to evaluate Lead + /// The offset (expressed as a positive number) by which to lead each element of the sequence + /// The produced sequence of tuple + + public static IEnumerable<(TSource Item, TSource OffsetItem)> Lead(this IEnumerable source, int offset) + { + return Lead(source, offset, default, ValueTuple.Create); + } + + /// + /// Produces a sequence of tuple containing a pair of elements separated by a positive offset. + /// + /// + /// This operator evaluates in a deferred and streaming manner.
+ ///
+ /// The type of the elements in the source sequence + /// The sequence over which to evaluate Lead + /// The offset (expressed as a positive number) by which to lead each element of the sequence + /// A default value supplied for the leading element when none is available + /// The produced sequence of tuple + + public static IEnumerable<(TSource Item, TSource OffsetItem)> Lead(this IEnumerable source, int offset, TSource defaultLeadValue) + { + return Lead(source, offset, default, ValueTuple.Create); + } } } diff --git a/README.md b/README.md index 358cfbdb9..532973b4c 100644 --- a/README.md +++ b/README.md @@ -356,7 +356,7 @@ This method has 2 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 From 3f4cc26bc06e7db71cf5fb868d27aa1274bb9561 Mon Sep 17 00:00:00 2001 From: Orace Date: Fri, 8 Nov 2019 19:54:32 +0100 Subject: [PATCH 3/3] Update MoreLinq/Lead.cs Co-Authored-By: Atif Aziz --- MoreLinq/Lead.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MoreLinq/Lead.cs b/MoreLinq/Lead.cs index e2095878d..f7ed1a675 100644 --- a/MoreLinq/Lead.cs +++ b/MoreLinq/Lead.cs @@ -65,7 +65,7 @@ public static IEnumerable Lead(this IEnumerable _() { var leadQueue = new Queue(offset); - using var iter = source.GetEnumerator(); + var iter = source.GetEnumerator(); bool hasMore; // first, prefetch and populate the lead queue with the next step of