【发布时间】:2020-01-04 04:41:07
【问题描述】:
我是 Spring Reactive Project 的新手。使用中出现问题。 我有两个 Flux,一个有更多元素,比如
Flux<Integer> bigFlux = Flux.range(1, 10);
还有人喜欢
Flux<Integer> smallFlux = Flux.just(3, 7);
如何获取 bigFlux 中未出现在 smallFlux 中的元素? 我不知道该使用哪个运算符。
我试过了:
Flux<Integer> flux = bigFlux.filterWhen(one -> smallFlux.hasElement(one).map(a->!a));
但这并不明智,我通过复杂的操作得到了smallFlux,比如查询数据库,flatMap操作。这样,bigFlux中有多少个元素,这些操作会重复多少次。
其实smallFlux就是这样得到的。
Flux<File> usedFile = repository.findAll()
.flatMap(one -> {
List<File> used = someMethods(one);
return Flux.fromIterable(used);
});
还有其他更好的解决方案吗,谢谢。
【问题讨论】: