June 2017
Intermediate to advanced
400 pages
8h 44m
English
The distinct() operator will emit each unique emission, but it will suppress any duplicates that follow. Equality is based on hashCode()/equals() implementation of the emitted objects. If we wanted to emit the distinct lengths of a string sequence, it could be done as follows:
import io.reactivex.Observable;public class Launcher { public static void main(String[] args) { Observable.just("Alpha", "Beta", "Gamma", "Delta", "Epsilon") .map(String::length) .distinct() .subscribe(i -> System.out.println("RECEIVED: " + i)); }}
The output of the preceding code snippet is as follows:
RECEIVED: 5RECEIVED: 4RECEIVED: 7
Keep in mind that if you have a wide, diverse spectrum of unique values, distinct() can use a bit of memory. Imagine that ...
Read now
Unlock full access