Skip to content

IEnumerable Tuple GetEnumerator #43687

Description

@Logerfo

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-System.LinquntriagedNew issue has not been triaged by the area owner

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions