[ANN] Kotlin support for RxJava


RxJava gets Kotlin support


Actually no specific support is needed, just SAM support is enough. But I add a set of Extension Functions just for fun


You can check the tests without extensions and with extensions.

Enjoy it


Looks cool!



The Observable class (and a few other classes) have static and non-static methods
that expect parameters of type Func0, Func1, etc and Action0, Action1, etc.

Have you considered making them more idiomatic Kotlin with extension functions
such as:

fun <T> Observable<T>.subscribe(onNext: (T) -> Unit): Subscription {
  return this.subscribe(object: Action1<T> {
  override fun call(t: T?): Unit = onNext(t as T)
  }) as Subscription




Theorically due to SAM constructs you don’t need an Extension Method to achieve that. For example:

fun received<T>(): (T?) -> Unit {
  return {(result: T?) -> a!!.received(result) }

listOf(1, 2, 3).asObservable().filter { it!! >= 2 }!!.subscribe(received())

As you see fitler and subscribe functions are able to receive functions (fitler receive a (T?) -> Boolean and susbscribe a (T?) -> Unit) as parameters

Obviously I didn’t cover every specific function with my tests (This is something that I plan to do at some point) but as far a I see SAM constructs works fine.

Notice that I provide some Extension functions https://github.com/MarioAriasC/RxJava/blob/master/language-adaptors/rxjava-kotlin/src/main/kotlin/rx/lang/kotlin/namespace.kt but just for convert easily from Kotlin types to Observables

If you have any specific example where this approach is not enough, please ping me back here