-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Proposal: Infix Concatenation Operator for IEnumerable<T> #7884
Comments
Being that |
Definitely good to know. Although, nobody in their right mind would ever guess Edit: I'm definitely not seeing O(n^2) for |
@dubrowgn the N is the number of |
@orthoxerox Ah my mistake. It still seems to me this should be addressed though. |
I'm not sure I understand the point/justification on that blog post. Take this modified example:
and this:
The number of elements has weight on the execution time. It's not just the number o enumerables. The number of yields is directly related to the number of elements. |
@paulomorgado I'm not sure what is it that you don't understand. Of course increasing the number of elements increases execution time, but it increases linearly, as you would expect, and it can't be improved. But when increasing the number of enumerables, the time increases quadratically. That's not what most people would except, and it can be improved. In other words, the total time it takes to enumerate the result of concating n sequences, each having m elements with the current implementation of |
For immutable lists this would make sense but not just any |
@dubrowgn #15 is the original issue covering the problem of naive recursive In this specific case, you can write your own |
@orthoxerox I don't believe it's correct to say the team knows how to fix it. There are a lot of tradeoffs. See this discussion from CodePlex. |
@dsaf #6136 would be awesome, and solve a bunch of other annoyances as well. I think that would probably be the way to do this. @alrz This is really just sugar on top of @orthoxerox Good to know the issue got some attention already. I had a similar thought about using linked lists instead of trees, since |
@dubrowgn Well, |
@dubrowgn It makes sense if used appropriately (eg, not in loops). Making it into an operator gives an implicit signal to the developer "hey, this is the right way to do this!" after which the developer often assumes that since its the "right" way, they don't have to worry about performance implications. If you're using it so often that making it an operator would really be helpful to you, perhaps you should reconsider if you're really using it appropriately in the first place. In this vein, some people feel having |
@MgSam I definitely understand the concern, and currently that makes sense. However, adding the So, a couple of thoughts. First, consistency matters. If a sequence of chars gets an operator, a sequence of anything else should be able to use the same operator with similar assumptions. Right now strings get special treatment, and |
In fact, quite the opposite. The only optimizations the compiler does are to join compile-time constant strings. Concatenation of lots of strings using From a performance perspective, I personally feel string IEnumerable does not have a similar position. The typical application should rarely, if ever, be doing |
I was talking about string operations in general, in code.
It's only wasteful if you concatenate more than once in succession. Plus, most of
We do it all the time, just not with |
These are all different operations, each with different effects and performance characteristics. The similarity ends at the conceptual level of "putting something new in a datastructure". You inadvertently make another point at why overloading |
Of course they have different performance characteristics. The point is, we add items to collections, and collections to other collections. Saying |
The existence of those methods is why Notice that the BCL lacks |
You have to store all of the results at once to use existing data structures. The whole point of enumerating items one at a time, is that you don't have to have them all in memory at once. |
Just for reference I'll link the Microsoft research paper about a non-quadratic implementation of |
We are now taking language feature discussion on https://github.com/dotnet/csharplang for C# specific issues, https://github.com/dotnet/vblang for VB-specific features, and https://github.com/dotnet/csharplang for features that affect both languages. |
Basically, this would be a '+' infix operator for IEnumerable that works the same as it does for strings:
Somewhat related: #3673, as this could be implemented as a set of extension methods if #3673 was implemented.
The text was updated successfully, but these errors were encountered: