Background and Motivation
dotnet/csharplang#2197 (comment)
Proposed API
public static IEnumerator<(T1, T2)> GetEnumerator<T1, T2>(this (IEnumerable<T1> a, IEnumerable<T2> b) pair) => pair.a.Zip(pair.b, (a, b) => (a, b)).GetEnumerator();
For several arities, starting at two, it can go on:
public static IEnumerator<(T1, T2, T3, T4)> GetEnumerator<T1, T2, T3, T4>(this (IEnumerable<T1> a, IEnumerable<T2> b, IEnumerable<T3> c, IEnumerable<T4> d) pair)
=> pair.a.Zip(pair.b, (a, b) => (a, b)).Zip(pair.c, (a, c) => (a.a, a.b, c)).Zip(pair.d, (a, d) => (a.a, a.b, a.c, d)).GetEnumerator();
I don't know where this could go, because GetEnumerator as extension methods is a new thing.
Usage Examples
foreach(var (a, b) in (collectionA, collectionB))
{
// This block will execute only while both `a` and `b` continue to yield values
// Code goes here
}
Background and Motivation
dotnet/csharplang#2197 (comment)
Proposed API
For several arities, starting at two, it can go on:
I don't know where this could go, because
GetEnumeratoras extension methods is a new thing.Usage Examples