-
Notifications
You must be signed in to change notification settings - Fork 36
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 FluxCountMapMathToIntExact
Refaster rule
#516
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.
Tnx @Ptijohn! Added a commit with some suggestions. Suggested commit message:
Introduce `FluxCountMapMathToIntExact` Refaster rule (#516)
@@ -805,6 +809,20 @@ Flux<T> after(Flux<? extends Iterable<T>> flux, int prefetch) { | |||
} | |||
} | |||
|
|||
/** Prefer {@link Flux#count()} over collecting into a list and counting its elements. */ | |||
static final class FluxCount<T> { |
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.
While it's an unwieldy name, likely we'll eventually name this rule FluxCountMapMathToIntExact
(based on the @AfterTemplate
code, so let's go for that.
static final class FluxCount<T> { | ||
@BeforeTemplate | ||
Mono<Integer> before(Flux<T> flux) { | ||
return flux.collect(toImmutableList()) |
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.
With CollectorMutability
we also suggest toCollection(ArrayList::new)
at times; let's add that case.
@BeforeTemplate | ||
Mono<Integer> before(Flux<T> flux) { | ||
return flux.collect(toImmutableList()) | ||
.map(Refaster.anyOf(Collection::size, ImmutableList::size, List::size)); |
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.
There's also ImmutableCollection::size
😄
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.
Of course!
Thanks :)
Collection::size, | ||
List::size, | ||
ImmutableCollection::size, | ||
ImmutableList::size)), |
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.
Sorted semi-hierarchically 🤷
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 I hesitated on this one 😅
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.
Changes LTGM! Nice PR @Ptijohn 🚀
FluxCount
Refaster rulesFluxCountMapMathToIntExact
Refaster rule
Suggested commit message: