December 2017
Intermediate to advanced
322 pages
7h 3m
English
Where the map operator takes each emission and transforms them, the flatMap operator creates a new producer, applying the function you passed to each emission of the source producer.
So, let's look at this example:
fun main(args: Array<String>) {
val observable = listOf(10,9,8,7,6,5,4,3,2,1).toObservable()
observable.flatMap {
number-> Observable.just("Transforming Int to String $number")
}.subscribe {
item-> println("Received $item")
}
}
Here is the output:

The output is similar to the previous one, but the logic is different. Instead of just returning the String, we are returning Observable with the desired String ...
Read now
Unlock full access