2

Comparing the values in Mono<Integer> a and Mono<Integer> b, if the value in Mono<Integer> a is larger, I want to throw an error.

Mono<Integer> a = getA();
Mono<integer> b = getB();

if(a > b) {
 throw new RuntimeException();
}
HooMin.Lee
  • 115
  • 1
  • 8
  • **What is your basis for comparison?** Example: I can compare two strings by looping over the characters of each string, comparing them one by one, and if there is a mismatch, comparing the two mismatching characters. Can you describe a similar process with `Mono` that satisfies your specific requirements? – Robert Harvey Mar 13 '21 at 16:38
  • @RobertHarvey I just want to compare the size of the `Integer` value in `Mono` – HooMin.Lee Mar 13 '21 at 16:46
  • Is this what you're referring to? https://www.codingame.com/playgrounds/929/reactive-programming-with-reactor-3/Mono – Robert Harvey Mar 13 '21 at 16:55
  • @RobertHarvey It seems different, but I solved it with the answer below. Thank you for letting me know a good site. – HooMin.Lee Mar 13 '21 at 17:19

1 Answers1

3
Mono<Integer> a = Mono.just(12);
Mono<Integer> b = Mono.just(10);

a.zipWith(b)
    .doOnNext(tuple -> {
        if (tuple.getT1() > tuple.getT2()) {
            throw new RuntimeException();
        }
    }).subscribe();
Alan Rusnak
  • 201
  • 1
  • 4