Skip to content
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

[Feature]: #963

Open
jbooth88 opened this issue Dec 6, 2024 · 2 comments
Open

[Feature]: #963

jbooth88 opened this issue Dec 6, 2024 · 2 comments

Comments

@jbooth88
Copy link

jbooth88 commented Dec 6, 2024

Describe the functionality desired 🐞

With the .Sort() method being depreciated there are a couple of rare cases where applying a sort immediately is desired because the properties used in the comparison do not exist downstream.

example:

    changeSet
            .Sort(complexSortComparer) //Sorts on input data type
            .DistinctValues(x => x.Name) //DistinctValues is transforming to Name data type 
            .Bind(out names); //List of names is sorted 

Changing the call chain to use SortAndBind() is not possible in this scenario.

I had a conversation on Slack about this topic:
https://reactivex.slack.com/archives/C4LF8S19N/p1733511277945719

The steps the functionality will provide

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Considerations

SortAndBind

@JakenVeina
Copy link
Collaborator

Additional scenarios we discussed...

using var subscription = changes
    .Sort()
    .Transform() // Does not preserve properties needed for sorting
    .Bind()
    .Subscribe();
var sharedChanges = changes
    .Sort()
    .Publish();
    
using var subscription1 = sharedChanges
    .Bind()
    .Subscribe();
    
using var subscription2 = sharedChanges
    .Bind()
    .Subscribe();
    
using var connection = sharedChanges
    .Connect();

The second scenario is pretty compelling to me, as a potential performance improvement for not duplicating sort work. However, I also proposed in the thread that the performance of .Sort() is so poor that one instance of .Sort() might actually NOT be more efficient thant two instances of .SortAndBind(). Now, I'm curious to benchmark it.

@jbooth88
Copy link
Author

jbooth88 commented Feb 3, 2025

I think I came across another scenario where there's a use case for sorting before binding. If the output collection is a base type, but the observable stream coming in is a derived type.

If there's an elegant work around I'm not seeing, please let me know :)

protected void example(ISourceCache<DerivedType, int> cache)
{
    cache
        .Connect()
        .Sort(derivedTypeSort)
        .Transform(x => (BseType)x)
        .ObserveOn(uiScheduler)
        .Bind(out collection)
        .Subscribe()
        .DisposeWith(this);
}
private ReadOnlyObservableCollection<BaseType> collection;
public IObservable<SortExpressionComparer<DerivedType>> DerivedTypeSort => //Sort impl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants