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

Add Refaster rule for Flux#concat for a single Mono or Flux #20

Merged
merged 3 commits into from
Nov 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,32 @@ Flux<S> after(Mono<T> mono) {
}
}

/** Don't use {@link Flux#concat(Publisher)} with only a single {@link Mono}. */
static final class FluxConcatMono<T> {
werli marked this conversation as resolved.
Show resolved Hide resolved
@BeforeTemplate
Flux<T> before(Mono<T> mono) {
return Flux.concat(mono);
}

@AfterTemplate
Flux<T> after(Mono<T> mono) {
return mono.flux();
}
}

/** Don't use {@link Flux#concat(Publisher)} with only a single {@link Flux}. */
static final class FluxConcatFlux<T> {
@BeforeTemplate
Flux<T> before(Flux<T> flux) {
return Flux.concat(flux);
}

@AfterTemplate
Flux<T> after(Flux<T> flux) {
return flux;
}
}

/**
* Prefer a collection using {@link MoreCollectors#toOptional()} over more contrived alternatives.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ Flux<String> testMonoFlatMapToFlux() {
return Mono.just("foo").flatMapMany(s -> Mono.just(s + s));
}

Flux<String> testFluxConcatMono() {
return Flux.concat(Mono.just("foo"));
}

Flux<String> testFluxConcatFlux() {
return Flux.concat(Flux.just("foo", "bar"));
werli marked this conversation as resolved.
Show resolved Hide resolved
}

ImmutableSet<Mono<Optional<String>>> testMonoCollectToOptional() {
return ImmutableSet.of(
Mono.just("foo").map(Optional::of).defaultIfEmpty(Optional.empty()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ Flux<String> testMonoFlatMapToFlux() {
return Mono.just("foo").flatMap(s -> Mono.just(s + s)).flux();
}

Flux<String> testFluxConcatMono() {
return Mono.just("foo").flux();
}

Flux<String> testFluxConcatFlux() {
return Flux.just("foo", "bar");
}

ImmutableSet<Mono<Optional<String>>> testMonoCollectToOptional() {
return ImmutableSet.of(
Mono.just("foo").flux().collect(toOptional()),
Expand Down