user2836797
user2836797

Reputation:

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

Upvotes: 1

Views: 530

Answers (1)

crgarridos
crgarridos

Reputation: 9263

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) }

Upvotes: 2

Related Questions