Example code :
public static IObservable<Order> ObserveOrders(this IProxy proxy,IEqualityComparer<Order> distinctPerDayComparer )
{
return Observable.FromEvent<Order>(ev => proxy.OrderUpdated += ev,ev => proxy.OrderUpdated -= ev)
.Distinct(distinctPerDayComparer);
}
public class DistinctPerDayComparer : IEqualityComparer<Order>
{
public bool Equals(Order o1, Order o2)
{
if(o1.Id != o2.Id)
return false;
bool isSameDay = o1.Date.Day == o2.Date.Day;
return isSameDay;
}
public int GetHashCode(Order o)
{
return o.Id.GetHashCode();
}
}
public class Order
{
public int Id { get; set; }
public DateTime Date { get; set; }
}
Scenario :
Sequence :
{id:1,D:'5/25/2016'}-{id:1,D:'5/25/2016'}-{id:2,D:'5/25/2016'}-{id:1 ,D:'5/26/2016'}
Distinct Sequence :
{id:1,D:'5/25/2016'}-{id:2,D:'5/25/2016'}-{id:1,D:'5/26/2016'}
Now assume that this sequence is long running, in fact onComplete is never called.
How does Rx manage it so it does not hold all the distinct elements in memory to compare with ?
I'm guessing it holds some back storage for elements in it's pipeline. but i always figured that after onNext is called with the next item that item is simply disposed.
Still if it's disposed what elements does Rx use for the EqualityComparer when calling the Distinct operator ?