usmanm77 / morelinq

Automatically exported from code.google.com/p/morelinq
Apache License 2.0
0 stars 0 forks source link

IEnumerable.SelectPairs() #79

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi I was wondering if it would be possible to include Jon's SelectPairs() 
extension from http://stackoverflow.com/a/619180/91551 ? Code below:

using System.Collections.Generic;

// This must be a non-nested type, and must be static to allow the extension
// method.
public static class Extensions
{
    public static IEnumerable<TResult> SelectPairs<TSource, TResult>
        (this IEnumerable<TSource> source,
         Func<TSource, TSource, TResult> selector)
    {
        using (IEnumerator<TSource> iterator = source.GetEnumerator())
        {
           if (!iterator.MoveNext())
           {
               yield break;
           }
           TSource prev = iterator.Current;
           while (iterator.MoveNext())
           {
               TSource current = iterator.Current;
               yield return selector(prev, current);
               prev = current;
           }
        }
    }
}

Original issue reported on code.google.com by rdingw...@gmail.com on 12 Dec 2012 at 1:59

GoogleCodeExporter commented 9 years ago
Code attached even. Added XML comments and your license at the top.

Original comment by rdingw...@gmail.com on 12 Dec 2012 at 2:00

GoogleCodeExporter commented 9 years ago

Original comment by rdingw...@gmail.com on 12 Dec 2012 at 2:01

Attachments:

GoogleCodeExporter commented 9 years ago
It's already there and it's called Pairwise:
http://code.google.com/p/morelinq/source/browse/MoreLinq/Pairwise.cs?name=1.0.15
416-beta

If you are using the NuGet package, update to the pre-release:
http://nuget.org/packages/morelinq/1.0.15416-beta

Original comment by azizatif on 12 Dec 2012 at 5:58

GoogleCodeExporter commented 9 years ago
Ah oops - thanks!

Original comment by rdingw...@gmail.com on 12 Dec 2012 at 7:05