Skip to content

[API Implementation]: Add Order and OrderDescending to Enumerable and Queryable - #70525

Merged
eiriktsarpalis merged 19 commits into
dotnet:mainfrom
deeprobin:issue-67194
Jun 30, 2022
Merged

[API Implementation]: Add Order and OrderDescending to Enumerable and Queryable#70525
eiriktsarpalis merged 19 commits into
dotnet:mainfrom
deeprobin:issue-67194

Conversation

@deeprobin

@deeprobindeeprobin commented Jun 9, 2022

Copy link
Copy Markdown
Contributor

Proposal implementation of #67194 (closes#67194)

Proposal

namespaceSystem.Linq{publicpartialclassEnumerable{publicstaticIOrderedEnumerable<T>Order<T>(thisIEnumerable<T>source);publicstaticIOrderedEnumerable<T>Order<T>(thisIEnumerable<T>source,IComparer<T>comparer);publicstaticIOrderedEnumerable<T>OrderDescending<T>(thisIEnumerable<T>source);publicstaticIOrderedEnumerable<T>OrderDescending<T>(thisIEnumerable<T>source,IComparer<T>comparer);}publicpartialclassQueryable{[DynamicDependency("Order`1",typeof(Enumerable))]publicstaticIOrderedQueryable<T>Order<T>(thisIQueryable<T>source);[DynamicDependency("Order`1",typeof(Enumerable))]publicstaticIOrderedQueryable<T>Order<T>(thisIQueryable<T>source,IComparer<T>comparer);[DynamicDependency("OrderDescending`1",typeof(Enumerable))]publicstaticIOrderedQueryable<T>OrderDescending<T>(thisIQueryable<T>source);[DynamicDependency("OrderDescending`1",typeof(Enumerable))]publicstaticIOrderedQueryable<T>OrderDescending<T>(thisIQueryable<T>source,IComparer<T>comparer);}}

Current state of implementation

  • Proposal implementation
  • Ref assembly
  • Tests 1
  • Documentation 2
  • .NET announcement

/cc @terrajobst

Footnotes

  1. I have implemented only the most important test cases, as I would imagine that the complex cases are flaky.
    If desired, I can also implement more test cases.

  2. Copied from the Microsoft Docs from the OrderBy overloads and adjusted accordingly.

@ghost

ghost commented Jun 9, 2022

Copy link
Copy Markdown

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghostghost added the community-contribution Indicates that the PR has been added by a community member label Jun 9, 2022
@ghost

ghost commented Jun 9, 2022

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/area-system-linq
See info in area-owners.md if you want to be subscribed.

Issue Details

Proposal implementation of #67194 closes #67194)

Proposal

namespaceSystem.Linq{publicpartialclassEnumerable{publicstaticIOrderedEnumerable<T>Order<T>(thisIEnumerable<T>source);publicstaticIOrderedEnumerable<T>Order<T>(thisIEnumerable<T>source,IComparer<T>comparer);publicstaticIOrderedEnumerable<T>OrderDescending<T>(thisIEnumerable<T>source);publicstaticIOrderedEnumerable<T>OrderDescending<T>(thisIEnumerable<T>source,IComparer<T>comparer);}publicpartialclassQueryable{// Or whatever's correct.[DynamicDependency("Order`1",typeof(Enumerable))]publicstaticIOrderedQueryable<T>Order<T>(thisIQueryable<T>source);[DynamicDependency("Order`1",typeof(Enumerable))]publicstaticIOrderedQueryable<T>Order<T>(thisIQueryable<T>source,IComparer<T>comparer);[DynamicDependency("OrderDescending`1",typeof(Enumerable))]publicstaticIOrderedQueryable<T>OrderDescending<T>(thisIQueryable<T>source);[DynamicDependency("OrderDescending`1",typeof(Enumerable))]publicstaticIOrderedQueryable<T>OrderDescending<T>(thisIQueryable<T>source,IComparer<T>comparer);}}

Current state of implementation

  • Proposal implementation 1
  • Ref assembly
  • Tests 2
  • Documentation 3
Author:deeprobin
Assignees:-
Labels:

area-System.Linq, new-api-needs-documentation

Milestone:-

Footnotes

  1. One possibility would of course be to simply forward Order to OrderBy(static item => item), but I guess this won't be really performant, so I implemented it this way (using OrderedKeylessEnumerable).
    I would like to get some feedback.

  2. I have implemented only the most important test cases, as I would imagine that the complex cases are flaky.
    If desired, I can also implement more test cases.

  3. Copied from the Microsoft Docs from the OrderBy overloads and adjusted accordingly.

@rhuijben

Copy link
Copy Markdown
Contributor

I don't think there is no way queryable can implement this new API in a more performant way than enumerable now does, as there is no documented way to introspect the comparer and somehow handle that on a repository layer.

In that case: is it useful to add the helper on Queryable?

Comment threadsrc/libraries/System.Linq/src/System/Linq/OrderBy.cs
Comment threadsrc/libraries/System.Linq.Queryable/tests/OrderTests.cs
Comment threadsrc/libraries/System.Linq/src/System/Linq/OrderBy.cs Outdated
Comment threadsrc/libraries/System.Linq/src/System/Linq/OrderBy.cs Outdated
Comment threadsrc/libraries/System.Linq/src/System/Linq/OrderBy.cs Outdated
Comment threadsrc/libraries/System.Linq/src/System/Linq/OrderBy.cs Outdated
Comment threadsrc/libraries/System.Linq/src/System/Linq/OrderBy.cs Outdated
Comment threadsrc/libraries/System.Linq/src/System/Linq/OrderBy.cs Outdated
Comment threadsrc/libraries/System.Linq/src/System/Linq/OrderBy.cs Outdated
Comment threadsrc/libraries/System.Linq/src/System/Linq/OrderedEnumerable.cs Outdated
Comment threadsrc/libraries/System.Linq/src/System/Linq/OrderedEnumerable.cs Outdated
@eiriktsarpaliseiriktsarpalis added the needs-author-action An issue or pull request that requires more info or actions from the author. label Jun 21, 2022
@ghostghost removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Jun 21, 2022
Comment threadsrc/libraries/System.Linq/src/System/Linq/OrderBy.cs Outdated
Comment threadsrc/libraries/System.Linq/src/System/Linq/OrderBy.cs Outdated
Comment threadsrc/libraries/System.Linq/src/System/Linq/OrderBy.cs Outdated
Comment threadsrc/libraries/System.Linq/src/System/Linq/OrderBy.cs
Comment threadsrc/libraries/System.Linq/src/System/Linq/OrderBy.cs Outdated
@deeprobin

Copy link
Copy Markdown
ContributorAuthor

; expected
@eiriktsarpalis If you like you can fix the semicolons. I would get to it this evening (CET) at the earliest.

Comment threadsrc/libraries/System.Linq/src/System/Linq/OrderBy.cs Outdated
@eiriktsarpalis

Copy link
Copy Markdown
Member

; expected

Ugh. I copied and pasted the code from main but it looks like fat arrow formatting was different. Should be fixed now.

@deeprobin

Copy link
Copy Markdown
ContributorAuthor

@eiriktsarpalis Thank you. I think this is ready-to-merge. Or do you have concerns (then we could ask a 2nd reviewer)?

@deeprobin

Copy link
Copy Markdown
ContributorAuthor

I think this API might not be bad for the announcements in the next preview version. Many people work with LINQ so this is probably a relatively interesting API.

@eiriktsarpalis

Copy link
Copy Markdown
Member

@deeprobin Would you like to add a short announcement in the Preview 7 issue?

dotnet/core#7455

@deeprobin

Copy link
Copy Markdown
ContributorAuthor

@eiriktsarpalis

Copy link
Copy Markdown
Member

suggestions?

Looks good overall, I would skip the API shape and just focus on the final code sample. It should be enough to communicate the background and motivation.

@deeprobin

Copy link
Copy Markdown
ContributorAuthor

suggestions?

Looks good overall, I would skip the API shape and just focus on the final code sample. It should be enough to communicate the background and motivation.

I removed the api shape 👍🏼

@eiriktsarpalis

Copy link
Copy Markdown
Member

Thanks @deeprobin !

@eiriktsarpalis
eiriktsarpalis merged commit 436ee2e into dotnet:mainJun 30, 2022
@ghostghost locked as resolved and limited conversation to collaborators Jul 31, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Linqcommunity-contributionIndicates that the PR has been added by a community membernew-api-needs-documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: Enumerable.Order and OrderDescending

4 participants

@deeprobin@rhuijben@eiriktsarpalis@gfoidl