是否可以过滤并继续编辑以下项目?
我的代码两次调用订户:

Observable<Map.Entry<String, ArrayList<MockOverview>>> requestEntries =
        this.requestView.request(request)
        .map(HashMap::entrySet)
        .flatMapIterable(entries -> entries);

requestEntries.filter(entry -> entry.getKey().equals("featured"))
        .map((Func1<Map.Entry<String, ArrayList<MockOverview>>, List<MockOverview>>) Map.Entry::getValue)
        .subscribe(mockOverviews -> {
            Log.i("subscrive", "featured");
        });

requestEntries.filter(entry -> entry.getKey().equals("done"))
        .map((Func1<Map.Entry<String, ArrayList<MockOverview>>, List<MockOverview>>) Map.Entry::getValue)
        .subscribe(mockOverviews -> {
            Log.i("subscrive", "featured");
        });

我想要的是:
 requestEntries.filter(entry -> entry.getKey().equals("featured"))
        .map((Func1<Map.Entry<String, ArrayList<MockOverview>>, List<MockOverview>>) Map.Entry::getValue)
        .subscribe(mockOverviews -> {

        })
        .filter(entry -> entry.getKey().equals("done"))
        .map((Func1<Map.Entry<String, ArrayList<MockOverview>>, List<MockOverview>>) Map.Entry::getValue)
        .subscribe(mockOverviews -> {

        });

最佳答案

您可以使用doOnNext代替第一个subscribe()

 requestEntry.filter(v -> ...)
 .map(v -> ...)
 .doOnNext(v -> ...)
 .filter(v -> ...)
 .map(v -> ...)
 .subscribe(...)


或使用publish(Func1)

 requestEntry.filter(v -> ...)
 .map(v -> ...)
 .publish(o -> {
     o.subscribe(...);
     return o;
 })
 .filter(v -> ...)
 .map(v -> ...)
 .subscribe(...)

关于java - RxJava过滤并发出其他项,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37307447/

10-13 03:21