Created
November 18, 2021 09:42
-
-
Save rnkoaa/4ba34782b9ba14a0361ee7b4976ec1e4 to your computer and use it in GitHub Desktop.
VAVR try to Reactor Conversion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Mono<Person> load(UUID id) { | |
return API.Match(tryLoadPerson(id)).of( | |
Case($Success($()), Mono::just), | |
Case($Failure($(instanceOf(IllegalArgumentException.class))), Mono::error), | |
Case($Failure($()), x -> Mono.error(new RuntimeException("unknown error"))) | |
); | |
} | |
private Try<Person> tryLoadPerson(UUID id) { | |
return API.Match(success()).of( | |
Case($(true), Try.success(new Person(UUID.randomUUID(), "Will Smith"))), | |
Case($(), Try.failure(new IllegalArgumentException("Unknown error"))) | |
); | |
} | |
private boolean success() { | |
return (int) (Math.random() * 2 + 1) < 2; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment