Skip to content

More arities for tuple returning zip extension method #43702

Description

@Logerfo

Background and Motivation

#43687 (comment)

Proposed API

namespace System.Linq
{
    public static class Enumerable
    {
+       public static IEnumerable<(TFirst First, TSecond Second, TThird Third)> Zip<TFirst, TSecond, TThird>(this IEnumerable<TFirst> first, IEnumerable<TSecond> second, IEnumerable<TThird> third);
    }

    public static class Queryable
    {
+       public static IQueryable<(TFirst First, TSecond Second, TThird Third)> Zip<TFirst, TSecond, TThird>(this IQueryable<TFirst> source1, IEnumerable<TSecond> source2, IEnumerable<TThird> source3);
    }
}

Usage Examples

foreach(var (a, b, c) in first.Zip(second, third))
{
   //...
}

Alternative Designs

public static IEnumerator<(T1, T2, T3)> GetEnumerator<T1, T2, T3>(this (IEnumerable<T1> a, IEnumerable<T2> b, IEnumerable<T3> c) pair)
    => pair.a.Zip(pair.b, (a, b) => (a, b)).Zip(pair.c, (a, c) => (a.a, a.b, c)).GetEnumerator();
foreach(var (a, b, c) in (collectionA, collectionB, collectionC)) 
{
	// This block will execute only while both `a`, `b` and `c` continue to yield values

	// Code goes here
}

Metadata

Metadata

Labels

api-approvedAPI was approved in API review, it can be implementedarea-System.Linqhelp wanted[up-for-grabs] Good issue for external contributors

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions