Suppose we have a subject that we use to publish some events
subject.onNext(...)
the end Subscriber is subscribed trough an Observable which was created from this subject...
I wonder if we can add some logic to observable so that if it gets the same value it wont propogate it to subscribers... or someting more complex..?
Is there a possibility to create an observable from subject that executes some code before emiting value to its subscribers?
There is a distinctUntilChanged
operator that skips a value if it was emitted more than once in a row.
If you need more general behaviour and want to skip values based on some condition, then filter
is probably what you are looking for.
Seems distictUntilChanged is exactly what is necessary in this case...
filter seems what i want but i dont really know how do i keep last value somewhere (unless i implement custom observable) and how do i access it to compare with new value?
You could use .buffer(2, 1).filter(...)
, so that filter
has access to the current and to the last element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With