1

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

  • Observable.fromIterable is a generic static function. In the way you're currently using it, you're not declaring the type params, so there's no way to resolve the generic type. When you pass a value in as a parameter, there is, but not in the use case you're providing, since you're not providing a param. – Submersed Jan 26 '18 at 19:53

1 Answers1

2

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) }
crgarridos
  • 8,758
  • 3
  • 49
  • 61