Converting RxJava to RxScala

582 Views Asked by At

Is there a way to use both RxJava and RxScala in one project?

import rx.lang.scala.{Observable => ScalaObservable}
import rx.{Observable => JavaObservable}

We have a module written in Java that is using the JavaObservable (RxJava). And then we have a Scala module that is supposed to use the Java module but is written in Scala.

Are there convenient methods to transform these into the other?

1

There are 1 best solutions below

0
On BEST ANSWER

Yes, this is possible by using the conversion functions such as toJavaObservable, toScalaObservable, etc in rx.lang.scala.JavaConversions.

You can either write the conversion explicitly (eg toJavaObservable(myScalaObservable), or if you enable implicit conversions and import rx.lang.scala.JavaConversions._, they will be inserted automatically by the compiler whenever a Java Observable is expected, but a Scala Observable is found, and vice versa.