问题
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 appropriate counterpart. I have Mono<List<String>> and I need to convert it to Flux<String>.
Thanks
回答1:
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.
回答2:
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).
回答3:
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);
来源:https://stackoverflow.com/questions/42007841/how-to-convert-monoliststring-into-fluxstring