英文:
How to collect Flux of Map into Mono of Map (Flux<Map<String,String>> into Mono<Map<String,String>>)?
问题
我找到了一个广泛的关于如何在Java8流中合并地图的线程,但我无法将其翻译成Webflux。
我有两个形式的Flux:
Flux<Map<String, List<String>>> fluxOne = Flux.fromIterable(
List.of(
Collections.singletonMap("one", List.of("one","two")),
Collections.singletonMap("two", List.of("one","two"))));
Flux<Map<String, String>> fluxTwo = Flux.fromIterable(
List.of(
Collections.singletonMap("one", "two"),
Collections.singletonMap("one", "two")));
我想通过收集其值将其转换为Mono:
Mono<Map<String, List<String>>> monoOne = fluxOne.collect(...);
Mono<Map<String, String>> monoTwo = fluxTwo.collect(...);
所以我的问题是,我该如何做到这一点?
英文:
I have found an extensive thread of how to merge maps in java8 streams, but I cannot quite translate that to Webflux.
I have two Fluxes of the form:
Flux<Map<String, List<String>>> fluxOne = Flux.fromIterable(
List.of(
Collections.singletonMap("one", List.of("one","two")),
Collections.singletonMap("two", List.of("one","two"))));
Flux<Map<String, String>> fluxTwo = Flux.fromIterable(
List.of(
Collections.singletonMap("one", "two"),
Collections.singletonMap("one", "two")));
I'd like to transform that into Mono's by collecting it's values:
Mono<Map<String, List<String>>> monoOne = fluxOne.collect(...);
Mono<Map<String, String>> monoTwo = fluxTwo.collect(...);
So my question, how do I do that?
答案1
得分: 0
也许这是您在寻找的:
Mono<Map<String, List<String>>> monoOne = fluxOne.collect(HashMap::new, Map::putAll);
Mono<Map<String, String>> monoTwo = fluxTwo.collect(HashMap::new, Map::putAll);
英文:
Perhaps this is what you are looking for:
Mono<Map<String, List<String>>> monoOne = fluxOne.collect(HashMap::new, Map::putAll);
Mono<Map<String, String>> monoTwo = fluxTwo.collect(HashMap::new, Map::putAll);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论