The transforming operators
As the name suggests, the transforming
operators help you transform items emitted by a producer.
Here is a brief list of transforming
operators:
map
flatMap
,concatMap
, andflatMapIterable
switchMap
switchIfEmpty
scan
groupBy
startWith
defaultIfEmpty
sorted
buffer
window
cast
delay
repeat
The map operator
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...