December 2017
Intermediate to advanced
322 pages
7h 3m
English
The map operator performs a given task (lambda) on each of the emitted items and emits them to the downstream. We have already seen a little use of the map operator. For a given Observable<T> or Flowable<T>, the map operator will transform an emitted item of type T into an emission of type R by applying the provided lambda of Function<T,R> to it.
So, now, let's take a look at another example with the map operator:
fun main(args: Array<String>) {
val observable = listOf(10,9,8,7,6,5,4,3,2,1).toObservable()
observable.map {//(1)
number-> "Transforming Int to String $number"
}.subscribe {
item-> println("Received $item")
}
}
On comment (1), we used the map operator, which will transform the emitted item of type Int to an emission ...
Read now
Unlock full access