-
Notifications
You must be signed in to change notification settings - Fork 39
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
Introduce MonoFromOptionalSwitchIfEmpty
and OptionalMapMonoJust
Refaster rules
#384
Conversation
Looks good. No mutations were possible for these changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for opening a PR!
Added one commit :)
Tweaked suggested commit message (a bit long, but alas):
Introduce `OptionalMapMonoJust` and `MonoFromOptionalSwitchIfEmpty` Refaster rules
(#384)
@BeforeTemplate | ||
Mono<T> before(Optional<T> optional, Mono<T> alternative) { | ||
return optional | ||
.map(Refaster.<Function<T, Mono<T>>>anyOf(Mono::just, Mono::justOrEmpty)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Mono::justOrEmpty
-> Mono::just
case can be its own "precursor rule", following our approach to defining the smallest improvement per Refaster rule. Will push a proposal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good one, thanks. I didn't see that initially.
Looks good. No mutations were possible for these changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got one question.
Besides that, no remarks. LGTM!
W.r.t. suggested commit message, LGTM as well.
} | ||
|
||
/** | ||
* Prefer a {@link Mono#justOrEmpty(Optional)} and {@link Mono#switchIfEmpty(Mono)} chain over |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is our usual way of defining the Javadoc.
However, it couldn't hurt to mention the exact reason either as @Description
or instead of over more contrived alternatives
. Not mixing the Optional
and Mono
API is a good argument and nice to document here as well.
We could IMO at least start with adding @Description
s here and there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can try to come up with something later today. 🤞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could IMO at least start with adding
@Description
s here and there.
I would defer that to a separate PR, as I'm still unsure about that feature. (Perhaps we can generate the @Description
annotation at compile time, based on the Javadoc: that would make for a much nicer developer experience.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go with Javadoc then, deal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebased and added a commit; PTAL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, would indeed feel like a different concern. Would have been weird starting this now in this PR. 🤔
bdd5290
to
25cdb6d
Compare
Build fails due to actions/setup-java#422... |
25cdb6d
to
5eee6b5
Compare
Looks good. No mutations were possible for these changes. |
MonoFromOptionalSwitchIfEmpty
Refaster ruleMonoFromOptionalSwitchIfEmpty
and OptionalMapMonoJust
Refaster rules
Swapped the order of the names to make 'em sorted 😉. |
I've spotted the following interesting pattern:
The mix between
Optional
andMono
API is unnecessary.These rules aim to rewrite these to:
Suggested commit message: