Search code examples
androidkotlinrx-javarx-java2rx-kotlin

Generic Function References in Rx and Kotlin -- type inference failed


I am writing a method in Kotlin:

fun fetchDepositSession(): Completable =
        Observable.fromIterable(session.accounts)
                .map(DepositSession::DepositAccount)
                .toList()
                .doOnSuccess(depositSession::depositAccounts::set)
                .flatMapObservable(Observable::fromIterable)
                .map(DepositSession.DepositAccount::account::get)
                .toCompletable()

The line .flatMapObservable(Observable::fromIterable) is causing an error:

enter image description here


Solution

  • RxJava and Kotlin inferring types don't work that well. There is a couple of issues like KT-13609 and KT-14984.

    See this question that is relative to the problem. There is also an issue in RxKotlin's Github talking about it.

    Anyway, you can always use:

    .flatMapObservable { Observable.fromIterable(it) }