I am trying to have a delete operation(r2dbc) using Webflux based on the condition as below, but switchIf empty is not working as expected. Specific Items are deleted successfully is getting printed always irrespective of filter condition satisfies or not.
Mono.just(cart).filter(cart1 -> CollectionUtils.isNotEmpty(cart1.getItems()))
.flatMapMany(cartV->Flux.fromIterable(cartV.getCartItems())).flatMap(items -> deleteItemsByIdName(id, items))
.then(Mono.just("Specific Items are deleted successfully")).log().switchIfEmpty(deleteAllItems(id).then(Mono.just("All Items are deleted successfully"))).log();
Kindly let me know, what I am missing here.. Or I need to change the logic completely?