Sort ObservableCollection values ​​(reactive extensions)

In my application, I have a list with over 400 push contacts. To avoid blocking the user interface, I use the following terminology along with the Rx frame.

var observer = localStoreCollection.ToObservable(); observer.Subscribe(StoresOnNext, StoresOnError, StoresOnCompleted); 

In OnNext, I will add these buttons one at a time to the binding list. Along with the map, I fill out the list with the same collection. So I need to sort this list based on the closest location. So my question is how can I sort this collection without rewriting the list. (A type of material similar to a call by reference).

NB: the distance is also set inside the OnNext method.

+4
source share
1 answer

A shot in the dark is here, since I have no idea what you are asking ...

edit ... just read your question with NB. Now, generally speaking, I would advise HIGH against the concept of using functional programming to assign values ​​to your data objects. Instead, I would advise you to create a new object that includes the PushPin and Distance property, or you use the map to store distance information as a kind of “Extension Property”.

 var observer = localStoreCollection.ToObservable(); observer.Subscribe(StoresOnNext, StoresOnError, StoresOnCompleted); var closestObservable = observer.Min(Comparer<PushPin>.Create((a, b) => Double.Comparer(Distance(a), Distance(b))); 

Or maybe even

 var observer = localStoreCollection.ToObservable(); observer.Subscribe(StoresOnNext, StoresOnError, StoresOnCompleted); var distanceMap = new ConcurrentDictionary<PushPin, double>(); var closestObservable = observer.Min(Comparer<PushPin>.Create((a, b) => Double.Comparer(distanceMap.GetOrAdd(a, Distance), distanceMap.GetOrAdd(b, Distance))); 

if the Distance(PushPin) function is expensive.

+1
source

Source: https://habr.com/ru/post/1487064/


All Articles