如何将 Mono 中的嵌套列表转换为 Flux?

How to convert nested list in Mono to Flux?

我对反应流很陌生,有人可以帮我把 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> 格式的乘数 *(每个)被乘数的结果。

你能帮我看看正确的做法吗?

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);
}