将反应过滤器包含到反应器链中

Include reactive filter to reactor chain

我有一个 Flux 对象,我需要使用反应式方法过滤它们。由于 filter 不支持响应类型,我该如何实现?

Flux<Student> students = ...
students
  .filter(this::leavesNearby)
  .collectList();  


Mono<Boolean> leavesNearby(Student student) {
   Address address = student.getAddress;    
   return addressService.isNearby(address);
}

考虑到addressService.isNearby(address)returnsMono<Boolean>,我在这一行有一个编译错误filter(this::leavesNearby)

您可以使用 filterWhen:

students
  .filterWhen(this::leavesNearby)
  .collectList();