简体   繁体   English

使用 rxJava 搜索编辑文本。 如何转换代码片段?

[英]Search edit text using rxJava. How to convert snippet of code?

I just copied snippet of code in java and automatically convert to kotlin using ide, but here is it my error: https://imgur.com/a/nHrVkDq I just copied snippet of code in java and automatically convert to kotlin using ide, but here is it my error: https://imgur.com/a/nHrVkDq

disposable.add(
                publishSubject
                        .debounce(300, TimeUnit.MILLISECONDS)
                        .distinctUntilChanged()
                        .switchMapSingle(new Function<String, Single<List<Contact>>>() {
                            @Override
                            public Single<List<Contact>> apply(String s) throws Exception {
                                return apiService.getContacts(null, s)
                                        .subscribeOn(Schedulers.io())
                                        .observeOn(AndroidSchedulers.mainThread());
                            }
                        })
                        .subscribeWith(observer));

Could you help me to convert it to kotlin?你能帮我把它转换成 kotlin 吗?

It should go like this:它应该像这样 go :

        disposable.add(
                publishSubject
                        .debounce(300, TimeUnit.MILLISECONDS)
                        .distinctUntilChanged()
                        .switchMapSingle { s ->
                            apiService.getContacts(null, s)
                                    .subscribeOn(Schedulers.io())
                                    .observeOn(AndroidSchedulers.mainThread())
                        }
                        .subscribeWith(observer))

Your Function must be coming from import io.reactivex.rxjava3.functions.Function您的Function必须来自import io.reactivex.rxjava3.functions.Function

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM