RxJava flatMapIterable with a Single

flattenAsObservable should do the trick, it will map Single success value to Iterable (list), and emit each item of the list as an Observable.

  getListOfItems()
            .flattenAsObservable(new Function<Object, Iterable<?>>() {
                @Override
                public Iterable<?> apply(@NonNull Object o) throws Exception {
                    return toItems(o);
                }
            })
            .flatMap(item -> doSomethingWithItem())
            .toList()

Leave a Comment