Tag: 反应编程

使用flatMap和filter过滤observables是否正确?

使用一个人为的例子来说明我的问题,我有一个复合对象types的Observable: Observable public class CategoryPayload { public List categories; // other meta data and getters } public class Category { public Integer id; // other meta data and getters } 我需要根据id过滤掉某些类别,所以我最终做了如下的事情: Observable categoryObservable = service.getCategoryPayload(); // use flatMap to transform the Observable into multiple mSubscription.add( categoryObservable.flatMap(new Func1<CategoryPayload, Observable>(){ public Observable call(CategoryPayload categoryPayload){ return Observable.from(categoryPayload.categories); } […]

Kotlingenerics方法和inheritance

在我的代码中,我想在抽象类中创建一个方法,该方法返回一些Observable。 然后这个抽象类的实现将返回某些(指定)types的Observable。 不幸的是,Android Studio会在实现方法()中返回一个错误“types不匹配”: 预计:可观察 find:Observable 我的MockDrawerList.getList()返回Observable 请关注execute()和buildUseCaseObservable 抽象类 public abstract class UseCase(threadExecutor: ThreadExecutor, postExecutionThread: PostExecutionThread) { private val threadExecutor: ThreadExecutor private val postExecutionThread: PostExecutionThread private var subscription: Subscription = Subscriptions.empty() init { this.postExecutionThread = postExecutionThread this.threadExecutor = threadExecutor } protected abstract fun buildUseCaseObservable(): Observable public fun execute(useCaseSubsriber: Subscriber) { subscription = buildUseCaseObservable() .subscribeOn(Schedulers.from(threadExecutor)) .observeOn(postExecutionThread.getScheduler()) […]