0
votes

This Object of Data include a String type of data, an ArrayList type of data.

 Flowable.just(rxjava.list1).concatMap(new Function<ArrayList<Data>, Publisher<Data>>() {
            @Override
            public Publisher<Data> apply(ArrayList<Data> data) throws Exception {
                return Flowable.fromIterable(data);
            }
        }).doOnNext(new Consumer<Data>() {
            @Override
            public void accept(Data data) throws Exception {
                Flowable.fromIterable(data.data).filter(new Predicate<String>() {
                    @Override
                    public boolean test(String s) throws Exception {
                        return "d".equals(s);
                    }
                }).subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String s) throws Exception {
                        System.out.println(data.name+" loop done");
                        data.name=data.name+"done";
                    }
                });
            }
        }).subscribe(new Consumer<Data>() {
            @Override
            public void accept(Data data) throws Exception {
                System.out.println("data name ==> "+data.name);
            }
        });

I want to do better. For example, easier for others to understand or code more concise. How to change?

1
First, explain what are you trying to do!! - Sarath Kn
just one looper nested another looper,i want to change to one chain but my code is one Flowable nested another Flowable .@SarathKn - user9000455

1 Answers

0
votes

Use concatMap:

Flowable.fromIterable(rxjava.list1)
.concatMap(data ->
    Flowable.fromIterable(data.data)
    .filter(s -> "d".equals(s))
    .doOnNext(s -> { data.name = data.name + "done" })
    .ignoreElements()
    .andThen(Flowable.just(data))
)
.subscribe(data -> {
     System.out.println("data name ==> "+data.name);
});