0
我有这样的伪数据低于我有很长一段时间停留在做一些RxJava代码更好的平均一些数据
class Place {
userId,
price
}
集合这意味着一些地方的集合。
用例:
有用户id和登录的用户。
如何计算等于userId的平均地点价格?
RxJava很好,我试过
filter
和toList
,但它不是那么好表现。Observable.fromIterable(places) .subscribeOn(Schedulers.newThread()) .filter(new Predicate<Place>() { @Override public boolean test(Place place) throws Exception { return place.userId == global.login.userId; } }) .toList() .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Consumer<List<Place>>() { @Override public void accept(List<Place> filteredPlace) throws Exception { //Here I have to use loop to do math-average, it is not nice to average. } });
我认为你的第一个代码也只是调用循环。你认为如果没有扩展名,只能在一行中写入吗? – TeeTracker
RxJava是一个组合库,其中的工具分布在内部,有时在外部。通常没有一个班轮可以解决一个不平凡的商业案例。由于您使用的是Android,因此您无法直接访问Java Streams,并且任何Java Streams backport都需要外部依赖项。 – akarnokd