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

Introduce FluxCountMapMathToIntExact Refaster rule #516

Merged
merged 2 commits into from
Mar 2, 2023

Conversation

Ptijohn
Copy link
Contributor

@Ptijohn Ptijohn commented Mar 1, 2023

Suggested commit message:

Introduce `FluxCount` Refaster rules (#516)

@Ptijohn Ptijohn requested a review from rickie March 1, 2023 12:27
@github-actions
Copy link

github-actions bot commented Mar 1, 2023

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Member

@Stephan202 Stephan202 left a 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> {
Copy link
Member

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())
Copy link
Member

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));
Copy link
Member

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 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course!
Thanks :)

@Stephan202 Stephan202 added this to the 0.9.0 milestone Mar 1, 2023
Comment on lines +826 to +829
Collection::size,
List::size,
ImmutableCollection::size,
ImmutableList::size)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorted semi-hierarchically 🤷

Copy link
Contributor Author

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 😅

@github-actions
Copy link

github-actions bot commented Mar 1, 2023

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Member

@rickie rickie left a 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 🚀

@rickie rickie changed the title Introduce FluxCount Refaster rules Introduce FluxCountMapMathToIntExact Refaster rule Mar 2, 2023
@rickie rickie merged commit ee265a8 into master Mar 2, 2023
@rickie rickie deleted the bdiederichs/flux-count branch March 2, 2023 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants