December 2017
Intermediate to advanced
322 pages
7h 3m
English
This operator is quite simple; it helps you filter duplicate emissions from the upstream. Take a look at the following example for better understanding:
fun main(args: Array<String>) {
listOf(1,2,2,3,4,5,5,5,6,7,8,9,3,10)//(1)
.toObservable()//(2)
.distinct()//(3)
.subscribe { println("Received $it") }//(4)
}
On comment (1), we created a list of Int containing many duplicate values. On comment (2), we created an Observable instance from that list with the help of the toObservable() method. On comment (3), we used the distinct operator to filter out all duplicate emissions.
Here is the output:
What the distinct operator does is remember all the emissions that took place and filters ...
Read now
Unlock full access