我对reactive-streams非常陌生,有人能帮我把Mono<MyClass>转换成Flux<Integer>吗
我试过这样的东西-
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;
}我期待Flux<Integer>格式的乘数*(每个)被乘数的结果。
你能帮助我做这件事的正确方法吗?
发布于 2019-05-18 02:20:27
将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);
}https://stackoverflow.com/questions/56191583
复制相似问题