[英]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
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));
你能幫我把它轉換成 kotlin 嗎?
它應該像這樣 go :
disposable.add(
publishSubject
.debounce(300, TimeUnit.MILLISECONDS)
.distinctUntilChanged()
.switchMapSingle { s ->
apiService.getContacts(null, s)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
}
.subscribeWith(observer))
您的Function
必須來自import io.reactivex.rxjava3.functions.Function
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.