February 2020
Intermediate to advanced
412 pages
9h 36m
English
The distinct() operator emits unique emissions. It suppresses any duplicates that follow. Equality is based on the hashCode() and equals() methods implemented by the emitted objects. If we want to emit the distinct lengths of strings, this could be done as follows:
import io.reactivex.rxjava3.core.Observable;public class Ch3_09 { public static void main(String[] args) { Observable.just("Alpha", "Beta", "Gamma") .map(String::length) .distinct() .subscribe(i -> System.out.println("RECEIVED: " + i)); }}
The output of the preceding code snippet is as follows:
RECEIVED: 5RECEIVED: 4
Keep in mind that if you have a wide, diverse spectrum of unique values, distinct() can use a bit of memory. Imagine that each subscription results in ...
Read now
Unlock full access