February 2020
Intermediate to advanced
412 pages
9h 36m
English
The distinctUntilChanged() function ignores consecutive duplicate emissions. If the same value is being emitted repeatedly, all the duplicates are ignored until a new value is emitted. Duplicates of the next value will be ignored until it changes again, and so on. Observe the output for the following code to see this behavior in action:
import io.reactivex.rxjava3.core.Observable;public class Ch3_11 { public static void main(String[] args) { Observable.just(1, 1, 1, 2, 2, 3, 3, 2, 1, 1) .distinctUntilChanged() .subscribe(i -> System.out.println("RECEIVED: " + i)); }}
The output of the preceding code snippet is as follows:
RECEIVED: 1RECEIVED: 2RECEIVED: 3RECEIVED: 2RECEIVED: 1
The first emission of 1 gets through to ...
Read now
Unlock full access