Rx Challenge #10 (Solution): DistinctUntilChanged with expiration period

added by DotNetKicks
9/2/2016 11:59:27 AM

2 Kicks, 462 Views

The solution for the DistinctUntilChanged challenge is: public static IObservable DistinctUntilChanged ( this IObservable source, Func keySelector, IEqualityComparer comparer, IObservable distinctPeriod) { var result = source.Publish(hot => { var distinct = hot.TakeUntil(distinctPeriod) .DistinctUntilChanged(keySelector, comparer) .Repeat(); return distinct; }); return result; } The idea is to cancel the district stream after a period and resume the subscription (repeat).