[英]How to convert nested list in Mono to Flux?
I am very new to reactive-streams, Can someone help me to convert Mono<MyClass>
to Flux<Integer>
我对反应流非常陌生,有人可以帮助我将
Mono<MyClass>
转换为Flux<Integer>
I tried something like this - 我尝试过这样的事情-
Flux<Integer> myMethod(Mono<MyClass> homeWork) {
return homeWork.map(h -> h.multiplicands)
.flatMapMany(Flux::fromIterable).map(m -> h*m);
}
public class MyClass{
int multiplier;
List<Integer> multiplicands;
}
I am expecting the result of multiplier * (each) multiplicand in Flux<Integer>
format. 我期望
Flux<Integer>
格式的乘数*(每个)被乘数的结果。
Can you help me with the correct way of doing this? 您能以正确的方式帮助我吗?
Transform the instance of MyClass
into a Stream<Integer>
which contains multiplied integers and then turn Mono<Stream<Integer>>
into Flux<Integer>
: 将
MyClass
的实例转换为包含乘法整数的Stream<Integer>
,然后将Mono<Stream<Integer>>
转换为Flux<Integer>
:
Flux<Integer> myMethod(Mono<MyClass> homeWork) {
return homeWork
.map(hw -> hw.multiplicands.stream().map(m -> m * hw.multiplier))
.flatMapMany(Flux::fromStream);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.