dotnet / standard

This repo is building the .NET Standard
3.07k stars 428 forks source link

Support of 'IAsyncComparer' for Linq operations. #1801

Closed Equijano24 closed 2 years ago

Equijano24 commented 2 years ago

Some Linq operations such as OrderBy or ThenBy might require asynchronous comparers for custom objects. Consider the following case:

public class ExoticObject {...}

public class ExoticComparer : IAsyncComparer<ExoticObject>
{
    public async ValueTask<int> Compare(ExoticObject e1, ExoticObject e2)
    {
        return await ..... // Some asynchronous code
    }
}

The following expression would make use of an asynchronous comparer:

IOrderedAsyncEnumerable<ExoticObject> orderedOnes =
    listOfExotics().OrderByAwait(SomeAsyncKeySelector, new ExoticComparer());

Please provide an IAsyncComparer interface and support for Linq operations.

svick commented 2 years ago
  1. .Net Standard is no longer being updated, this issue should be moved to dotnet/runtime.
  2. Can you explain why you need async code to compare two objects and why you think it's a common enough need to be included in .Net? Especially since you called the comparer "exotic", which seems to imply it doesn't happen often.
Equijano24 commented 2 years ago

I think this issue better belongs to dotnet/reactive, so I placed it now over there. If you agree you can close this issue here.

ericstj commented 2 years ago

I'll close this for now. If you do wish for changes to Linq API feel free to open an issue in dotnet/runtime.