-
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 additional Reactor Refaster rules #969
Conversation
Looks good. No mutations were possible for these changes. |
a8447b0
to
f12c569
Compare
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.
Cool stuff
|
||
@AfterTemplate | ||
Mono<T> after(Flux<T> flux) { | ||
return flux.transform(MathFlux::max).next(); |
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.
Food for thought: MathFlux#max
returns a Mono
, so the resulting Flux
has either zero or one element. Should we make this more explicit but using Flux#singleOrEmpty()
? This comment applies for more parts of the PR.
return flux.transform(MathFlux::max).next(); | |
return flux.transform(MathFlux::max).singleOrEmpty(); |
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.
Nice suggestion; applied!
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.
Maybe this opens up a box of other possible improvements.
Any conversion Mono -> Flux -> Mono
for which we know at most one element emitted and that's currently using Flux#next
should be rewritten? E.g. flux.transform(xyz -> mono).next()
could call Flux#singleOrEmpty()
.
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.
Indeed. There's a whole class of "replace operator based on an invariant established by preceding operators" rewrite rules, where these invariants are often of the form "between x
and y
elements will be emitted". In some cases it may be more efficient/practical to introduce an Error Prone check for that, like we did for NonEmptyMono
.
I was planning to add a commit with two more rules:
- One that matches your suggestion, with a note to generalize it later.
- Another that I came up with when writing a test case for the first. This one cleans up a pattern found in our codebase.
(The idea being that this is a lightweight approach to tracking these ideas.)
... however, the first of these rules doesn't work, due to what appears to be a bug in Refaster's matching of generic types. I previously hit a similar issue, so I added this rule to another branch.
f12c569
to
015c221
Compare
Looks good. No mutations were possible for these changes. |
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.
LGTM 👍🏻
ff27cbe
to
bf9ea3d
Compare
Looks good. No mutations were possible for these changes. |
In various contexts, suggest more efficient and/or less verbose constructs.
bf9ea3d
to
1c930ba
Compare
Looks good. No mutations were possible for these changes. |
Quality Gate passedKudos, no new issues were introduced! 0 New issues |
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!
@@ -608,7 +618,7 @@ Flux<S> before( | |||
} | |||
|
|||
@AfterTemplate | |||
Flux<S> after(Mono<T> mono, Function<? super T, ? extends Iterable<? extends S>> function) { |
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 also apply this in the other before template :).
EDIT: It doesn't work, because (correct me if I'm wrong): it doesn't make sense to go from something that is a super type of I
to something that is a subtype of I
, (or I
), right?
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.
Hmm, it could make sense, but using I
instead of ? extends Iterable<? extends S>
would impose a greater restriction than necessary or desired: the rule should also work for any Iterable
that is not a sub- or super-type of I
.
Suggested commit message: