35
votes

I'm converting small project written in RxJava 1.x to Reactor 3.x. All is good, except that I could not find out how to replace flatMap(Observable::from) with an appropriate counterpart. I have Mono<List<String>> and I need to convert it to Flux<String>.

3

3 Answers

76
votes

In Reactor 3, the from operator has been specialized into a few variants, depending on the original source (array, iterable, etc...).

Use yourMono.flatMapMany(Flux::fromIterable) in your case.

8
votes

I think that probably Flux::mergeSequential static factory fits better here:

 Iterable<Mono<String>> monos = ...
 Flux<String> f = Flux.mergeSequential(monos);

This kind of merge (sequential) will maintain the ordering inside given source iterable, and will also subscribe/request eagerly from all participating sources (so more parallelization expected while computing mono results).

4
votes

Thanks Simon, I implemented something like this:

List<Object> dbObjects = ListObjectsBD();
    List<Dao> daos = mapperObjToDao(dbObjects);
    Flux<Dao> daoFlux = Mono.just(daos).flatMapMany(Flux::fromIterable);