New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uni with Optional #138
Comments
At first glance, it looks like a bug. It should work. |
Ok, actually no it's normal. You need to help JAva a little bit:
|
Interestingly this works with the CompletionStage API (different piece of code, but "same typing"): @Override
public CompletionStage<Optional<UserDTO>> findUser(String email) {
Tuple values = Tuple.of(email);
return pgPool
.preparedQuery(FIND_USER_BY_EMAIL_RAW_SQL, values)
.thenApply(
pgRowSet -> {
if (!pgRowSet.iterator().hasNext()) {
return Optional.empty();
}
Row row = pgRowSet.iterator().next();
return Optional.of(
new UserDTO(
row.getUUID("id"),
row.getString("email"),
UserRole.valueOf(row.getString("role")),
row.getString("org")));
});
} |
Yes because you don't have the last "stage" (onFailure().invoke), so it is able to deduce the generic type. This would also work:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to map to Optionals using Unis?
This code will fails with the error:
The text was updated successfully, but these errors were encountered: