-
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] extend language integrated query clauses with "apply" clause #3571
Comments
I would really like something like this, since it's completely general. But I think the syntax needs to be fleshed out much more. Some questions:
|
'Apply' could be very good starting point for discussion. Call-like syntax is maybe more suitable for C# language.
When there are not parameters, is it good idea to allow both forms?
Some methods are natural after the final select.
Some methods can be after the final select.
But also can be proposed in infix notation.
Some methods are maybe more natural in infix notation (as in sql).
But also can be written on the end
|
Not all methods of I intentionally did not use a call-like syntax because that's how all existing clauses were defined. All the rules that apply now and to method invocation style would still apply. The fact that you don't have a |
Can we make a minimum subset of methods that are suitable for implementation? ... select expression apply ToList Is it good idea for the first time to avoid methods with parameters? |
Can you explain this example.
I don't understand how this query can be translated into pure methods chain. Does it mean
Maybe you thought
When we talk about Distinct we should have in mind how works default comparator. |
More precisely, I don't understand how to use 'apply' before 'select expression'. Now we can write 'where' more times between first 'from' and the last 'select'.
Do we think about this form of 'apply'?
Can we make a list of suitable methods in this case? |
The point of this proposal is to not be limited to any set of methods. And to allow methods with none or one parameter.
This:
will translate into:
On the other hand, this:
will translate into:
You can write this:
as this:
if you want to. |
Thank you. Very, very interesting. I will think more about that. |
That was a key.
Now, I understand better your proposal.
Yes. Now when I understand I agree with you regarding parameters. |
This is a piece of code from one of my old WinForms application.
Now we can write
Very nice. |
Element operations have Immediate Execution. These methods are always on the end of query or subquery.
Or in some form of possible infix notation. This notation can coexist with apply.
|
This group of my favourite methods have Immediate Execution. These methods are always on the end of query or subquery. ToArray, ToDictionary, ToList, ToLookup
|
Methods All and Any have Immediate Execution. These methods are always on the end of query or subquery. Here is one VB example.
And some F#.
I am not convinced that it is good to introduce special form of syntax for this purpose which exists in VB.
|
These methods have Immediate Execution. These methods are always on the end of query or subquery. Here is VB syntax.
And some F#
We can avoid special form of Aggregate syntax that exists in VB.
Some possible infix improvements that can coexist with apply.
|
Here is VB syntax.
And some F#
C# Examples
|
VB example
C# example
Or some possible alternatives.
@paulomorgado I am not sure that method Distinct has correct syntax.
|
Some examples in C# and F#
|
I was thinking of some of my extensions - LINQ: Enhancing Distinct With The SelectorEqualityComparer |
I strongly vote for this one. I never use LINQ language queries and instead my coding guidelines is avoid using them and always use the extension methods directly, and that's because the ugly parentheses each query has to be wrapped in order to materialize it ( Until this issue is addressed, language-build-in LINQ is merely useless. I'd say the syntax should provide an operator that expects a shortcutted extension method available for
Asynchronous methods should also be supported:
Maybe there should be a verbose LINQ fashioned way to pass the arguments and completely avoid the use of parenthesis, but I personally don't see it as necessary. Anyway this feature is crucial for the completeness of the LINQ syntax. Some suggestions above proposed the |
Issue moved to dotnet/csharplang #333 via ZenHub |
Every now and then there's a new request for a new query clauses (C#, Visual Basic).
Sometimes it's to add to C# some query clause that Visual Basic already has (Aggregate, Distinct, Skip, Skip While, Take, Take While), or materialization of the query (ToArray, ToList, ToDictionary or ToLookup) or soe other selection or aggregation (First, FirstOrDefault, Last, LastOrDefault, Single, SingleOrDefault, Count, etc.).
There are just too many and chances are that more will come.
How about extending the query language with an
apply
clause?This
apply
clause would be composed of anapply
keyword followed by the method name (instance or extension like already happens to Select or Where) and any other parameters.Then it would be possible to write something like this:
Or this:
Or this:
I don't know if I like this or not, but looks to me a lot more consistent and all-encompassing than individual proposals.
The text was updated successfully, but these errors were encountered: