O'Reilly logo

Learning Scala Programming by Vikash Sharma

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

Creating Observables

For creating Observables, there are a bunch of operators such as just, empty, interval, from, and defer. Let's first write some code to create Observables in some of the ways:

package example 
 
import rx.lang.scala.Observable 
import scala.concurrent.Future 
import scala.concurrent.ExecutionContext.Implicits.global 
import scala.concurrent.duration._  object FirstRxApp extends App { //Creates an empty Observable. val emptyObservable = Observable.empty //Creates an Observable that only emits 1. val numObservable = Observable.just(1) val sequence = List(1, 3, 5, 7, 9) //Creates an Observable, which emits values from the sequence mentioned. val sequenceObservable = Observable.from(sequence) val someAsyncComputation = Future { ...

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