-
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: Splatting #8987
Comments
I'd suggest the syntax for your first two examples would probably need to be: public double Avg(int sum, int count) => count == 0 ? 0 : sum / count;
Console.WriteLine($"Avg: {Avg(...Tally(myValues))}"); // ... means map tuple to two params of Avg And var list = List<(string name, int age)>();
list.Add(("John Doe", 66)); // inner () needed to denote it's a tuple, not two separate params |
@DavidArno That's the exact syntax proposed in #347. The rest of examples are my suggestions. |
Thanks. I've cross-referenced my suggestion there too. |
If |
@bondsbw I'm not fond of the syntax here, however, this is what ES, C++ and Java are actually using for various purposes. "it could completely change the meaning of many of the issues and proposals on in this forum" yeah actually it's kind of a breaking change ;). |
Moved to dotnet/csharplang#424 |
As it is proposed in #347 you might be able to use splatting in method arguments
And unsplatting would be like:
In the first case it's rather too implicit and as discussed, there should be some kind of operator to make it more visible.
I want to propose the ability to use this syntax on tuples themselves e.g.
In this case the target expression must be of a tuple type (names will be preserved in the resultant tuple).
Same syntax can be used with anonymous types.
This is specifically useful in pipeline processing (like LINQ) to compose short-lived tuples with additional information added in each step.
The text was updated successfully, but these errors were encountered: