score:3

Accepted answer

The standard Zip method allows you to write something like (using C#):

from t in first.Zip(second, (f, s) => new { First = f, Second = s }
select ... t.First ... t.Second;

I think this should be readable enough. Your question seems to suggest that you'd like to be able to create your own keyword e.g. zip and extend the C# query expressions using it. This is not possible in C# or Visual Basic (but I agree it would be nice in a way).

With some effort, you can redefine what standard C# query construct does, so that join would behave like zip (In that case, the equals part of the query would not be needed, so you'd have a lot of syntactic noise). Possibly, you could also redefine what from clause. I didn't try it, but I believe you could get something like:

from f in first.Zip()
from s in second.AddToZip()
from t in second.AddToZip()
select ... f ... s ... t ...;

I wrote an article that describes how to do this redefining for the group by clause (Using custom grouping operator in LINQ), so this can give you an idea how this can be done.

(But honestly, I think that the standard Zip method should be fine. The redefinition of operators is quite subtle. The group by example may be more appealing because grouping using method is uglier, but even that is on the edge...)


Related Query

More Query from same tag