-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More arities for tuple returning zip extension method #43702
Comments
Tagging subscribers to this area: @eiriktsarpalis, @jeffhandley |
Proposal looks good to me. To be determined: what is the maximum arity we are willing to support? |
Note that we would also need to include the reducing selecting overloads: namespace System.Linq
{
public static class Enumerable
{
public static IEnumerable<TResult> Zip<TFirst, TSecond, TThird, TResult>(this IEnumerable<TFirst> first, IEnumerable<TSecond> second, IEnumerable<TThird> third, Func<TFirst, TSecond, TThird, TResult> resultSelector);
public static IEnumerable<TResult> Zip<TFirst, TSecond, TThird, TFourth, TResult>(this IEnumerable<TFirst> first, IEnumerable<TSecond> second, IEnumerable<TThird> third, IEnumerable<TFourth> fourth, Func<TFirst, TSecond, TThird, TFourth, TResult> resultSelector);
...
}
} as well as the IQueryable variants: namespace System.Linq
{
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);
public static IQueryable<(TFirst First, TSecond Second, TThird Third, TFourth Fourth)> Zip<TFirst, TSecond, TThird, TFourth>(this IQueryable<TFirst> source1, IEnumerable<TSecond> source2, IEnumerable<TThird> source3, IEnumerable<TFourth> source4);
...
public static IQueryable<TResult> Zip<TFirst, TSecond, TThird, TResult>(this IQueryable<TFirst> first, IEnumerable<TSecond> second, IEnumerable<TThird> third, Expression<Func<TFirst, TSecond, TThird, TResult>> resultSelector);
public static IQueryable<TResult> Zip<TFirst, TSecond, TThird, TFourth, TResult>(this IQueryable<TFirst> first, IEnumerable<TSecond> second, IEnumerable<TThird> third, IEnumerable<TFourth> fourth, Expression<Func<TFirst, TSecond, TThird, TFourth, TResult>> resultSelector);
...
}
} @Logerfo would you be able to update your proposal? |
@eiriktsarpalis |
I'm not against this proposal, but I'm not sure how much value it adds, since you can do the following today: foreach (var ((a, b), c) in first.Zip(second).Zip(third)) |
@svick it adds value on legibility and succinctness and it grows with the arity: foreach (var ((((((a, b), c), d), e), f), g) in first.Zip(second).Zip(third).Zip(fourth).Zip(fifth).Zip(sixth).Zip(seventh))
foreach (var (a, b, c, d, e, f, g) in first.Zip(second, third, fourth, fifth, sixth, seventh)) |
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);
}
} |
I think that's a great decision. Zip itself is a fairly rare operation and zipping many sequences becomes rarer as the number grows. I also find the workaround |
@terrajobst your post still contains the |
OP updated. |
Background and Motivation
#43687 (comment)
Proposed API
Usage Examples
Alternative Designs
The text was updated successfully, but these errors were encountered: