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?
It should go like this:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.