Observable.combineLatest type inference in kotlin

为君一笑 提交于 2019-11-30 08:20:58
zsmb13

Your issue is that the compiler can't figure out which override of combineLatest to call, because multiple ones have functional interfaces as their third parameter. You can make the conversion explicit with a SAM constructor like this:

val isSignInEnabled: Observable<Boolean> = Observable.combineLatest(
        userNameObservable,
        passwordObservable,
        BiFunction { u, p -> u.isNotEmpty() && p.isNotEmpty() })

Ps. Thanks for asking this question, it helped me figure out that I was initially wrong about this one that turns out to be the same problem, which I've now updated with this solution as well. https://stackoverflow.com/a/42636503/4465208

You can use RxKotlin which gives you helper methods for SAM ambiguity issue.

val isSignInEnabled: Observable<Boolean> = Observables.combineLatest(
    userNameObservable,
    passwordObservable)
    { u, p -> u.isNotEmpty() && p.isNotEmpty() })

As you can see, in RxKotlin use Observables instead of Observable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!