O'Reilly logo

Scala Reactive Programming by Rambabu Posa

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

RxScala's map() function

Like the Scala language, RxScala also has a map() function. In RxScala, Observable's map() function returns an Observable that applies the given function to each item emitted by an Observable and emits the result. It is defined as follows:

def map[R](func: T => R): Observable[R] 

The following example demonstrates how Observable's map() function works:

RxScalaMapFunctionExample.scala:

import rx.lang.scala.Observable 
object RxScalaMapFunctionExample extends App { 
 
  val observable = Observable.just(1) 
 
  observable.map(x => x) 
} 

RxScala's map() function Marble diagram is represented as follows:

RxScala's distinct() function ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required