Skip to content
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

Refactor some usages of Optional #410

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

guillermocalvo
Copy link
Collaborator

Now that Optional instances are unified, we can refactor some usages to simplify and hopefully make the codebase easier to understand and maintain.

Examples
Before refactor After refactor
if (OPTIONAL.isPresent()) {
    return OPTIONAL.get().toString();
}
return "OTHER";
return OPTIONAL.map(Object::toString).orElse("OTHER");
if (OPTIONAL.isPresent()) {
   x.DO_SOMETHING(OPTIONAL.get());
}
OPTIONAL.ifPresent(x::DO_SOMETHING);

Note

Merging this PR should not add new features or alter existing functionality in any way. The main goal is to avoid both conditional branching and unwrapping optionals if the code is more readable without it. This results in a more idiomatic usage of Optional and reduces cyclomatic complexity.

@siom79 Please let me know your thoughts about this refactor. I understand readability may be subjective; there's no need to merge any of these changes if you are uncomfortable or unsure about them.

@guillermocalvo guillermocalvo self-assigned this Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant