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 FluxMapNotNull{,Transformation}OrElse Refaster rules #1493

Merged
merged 3 commits into from
Jan 2, 2025

Conversation

werli
Copy link
Member

@werli werli commented Dec 31, 2024

I want to advocate for using Flux#mapNotNull more, even if that includes defaulting to an explicit null value.

I'm happy to learn how to fuse those into one rule. 👀

Suggested commit message:

Introduce `FluxMapNotNull{,Transformation}OrElse` Refaster rules (#1493)

Copy link

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.

@werli werli marked this pull request as draft December 31, 2024 13:07
@Stephan202 Stephan202 force-pushed the werli/more-flux-map-null branch from 5821073 to 5cfb7ca Compare January 1, 2025 10:34
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.

Nice one @werli! I rebased and added a commit. Suggested commit message:

Introduce `FluxMapNotNull{,Transformation}OrElse` Refaster rules (#1493)


@BeforeTemplate
Flux<S> before(Flux<T> flux) {
return flux.map(x -> transformation(x)).mapNotNull(x -> x.orElse(null));
Copy link
Member

Choose a reason for hiding this comment

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

It turns out that the test for this rule currently fails because x is reused. Official Java scoping rules have these variables be independent, but I suspect that Refaster takes a shortcut somewhere. Good that we have tests :)

@@ -889,6 +889,35 @@ Flux<S> after(Flux<T> flux) {
}
}

/** Prefer {@link Flux#mapNotNull(Function)} over more contrived alternatives. */
Copy link
Member

Choose a reason for hiding this comment

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

Both variants use mapNotNull; will propose something.

@@ -889,6 +889,35 @@ Flux<S> after(Flux<T> flux) {
}
}

/** Prefer {@link Flux#mapNotNull(Function)} over more contrived alternatives. */
abstract static class FluxMapNotNullMapOptional<T, S> {
Copy link
Member

Choose a reason for hiding this comment

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

We're still figuring out our preferred naming strategy, but tentatively it'd be something like FluxMapNotNullOrElse. Since the rule below would yield the same name, perhaps we'd go for FluxMapNotNullTransformationOrElse here 🤔. Will use that for now.

@Stephan202 Stephan202 added this to the 0.20.0 milestone Jan 1, 2025
@Stephan202 Stephan202 requested a review from rickie January 1, 2025 10:35
@Stephan202 Stephan202 changed the title Introduce FluxMapNotNull(Map)Optional Refaster rules Introduce FluxMapNotNull{,Transformation}OrElse Refaster rules Jan 1, 2025
Copy link

github-actions bot commented Jan 1, 2025

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

sonarqubecloud bot commented Jan 1, 2025

@rickie rickie marked this pull request as ready for review January 2, 2025 07:25
@rickie
Copy link
Member

rickie commented Jan 2, 2025

As @Stephan202 was already reviewing and I don't see any open points; I dropped the draft status :)

@werli
Copy link
Member Author

werli commented Jan 2, 2025

Thanks @Stephan202 & @rickie - LGTM 👍

@Stephan202 Stephan202 merged commit e67800e into master Jan 2, 2025
16 checks passed
@Stephan202 Stephan202 deleted the werli/more-flux-map-null branch January 2, 2025 11:42
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