-
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: Support Signature Redefinition of an Anonymous Method #2675
Comments
Specific syntax aside, I don't understand what is the goal of all this. In what way is |
It's not directly, which is why I'm mostly spit-balling around the possibilities of something like this. This may have been better placed as a comment instead of an issue against the proposal thread. I guess ultimately what I'm asking is if there's a way of having some sort of partial application for anonymous methods to ease the need to explicitly call and pass arguments that aren't needed. |
@ckpearson DoSomething((_,_,x`) => myIntList.Add) very confusing. DoSomething((_,_val``,key`) => myDict.Add) its really confusing, especially if That said, I would really love, as you mention, for there to be some form of first class support for partial application. |
We are now taking language feature discussion on https:/dotnet/csharplang for C# specific issues, https:/dotnet/vblang for VB-specific features, and https:/dotnet/csharplang for features that affect both languages. |
Currently when providing a delegate, you can substitute a method group, so (types are included for visibility, I'm aware they can be omitted):
can be rewritten as:
This gets a bit tricky if you end up with a signature that has arguments you're not interested in at that point, e.g.
I'd like to be able to do something akin to:
whereby the signature of
(ignore,ignore,int)
matches the signature of(int)
and it all lines up nicely.Now, currently the
_
character is just practice, and can't be used multiple times, making it possible to do so would likely be a breaking change - I'm sure someone somewhere has actually referenced the_
argument against practice.I'd propose introducing a way to get around this:
I've used the backtick character against the argument I want to include in the redefinition, this allows:
_
as this is a redefinition so they can be forcibly made to not be referenceableThese redefined methods could enforce their assumptions by requiring a method group on the RHS, so the following would be invalid:
You could even introduce some sort of ordering notation to allow for the redefinition of signatures out-of-order, e.g:
OR
This is pretty trivial I realise, but it'd be one of those syntactic nice-to-haves and prevent having to explicitly write the anonymous method just because in this context I'm not interested in an argument.
A real-world example is the
XElement.Validate
linq extension method:The above could be rewritten to be:
Or a nicer syntax similar to the following could be used.:
The text was updated successfully, but these errors were encountered: