Skip to content

Commit

Permalink
Suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 authored and rickie committed Jan 20, 2024
1 parent 000d9cd commit 1c930ba
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1042,12 +1042,15 @@ Mono<S> after(Flux<T> flux, Mono<S> mono) {
/** Prefer {@link Mono#singleOptional()} over more contrived alternatives. */
// XXX: Consider creating a plugin that flags/discourages `Mono<Optional<T>>` method return
// types, just as we discourage nullable `Boolean`s and `Optional`s.
// XXX: The `mono.transform(Mono::singleOptional)` replacement is a special case of a more general
// rule. Consider introducing an Error Prone check for this.
static final class MonoSingleOptional<T> {
@BeforeTemplate
Mono<Optional<T>> before(Mono<T> mono) {
return Refaster.anyOf(
mono.flux().collect(toOptional()),
mono.map(Optional::of).defaultIfEmpty(Optional.empty()));
mono.map(Optional::of).defaultIfEmpty(Optional.empty()),
mono.transform(Mono::singleOptional));
}

@AfterTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ ImmutableSet<Mono<?>> testFluxThenMono() {
ImmutableSet<Mono<Optional<String>>> testMonoSingleOptional() {
return ImmutableSet.of(
Mono.just("foo").flux().collect(toOptional()),
Mono.just("bar").map(Optional::of).defaultIfEmpty(Optional.empty()));
Mono.just("bar").map(Optional::of).defaultIfEmpty(Optional.empty()),
Mono.just("baz").transform(Mono::singleOptional));
}

Mono<Number> testMonoCast() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,10 @@ ImmutableSet<Mono<?>> testFluxThenMono() {
}

ImmutableSet<Mono<Optional<String>>> testMonoSingleOptional() {
return ImmutableSet.of(Mono.just("foo").singleOptional(), Mono.just("bar").singleOptional());
return ImmutableSet.of(
Mono.just("foo").singleOptional(),
Mono.just("bar").singleOptional(),
Mono.just("baz").singleOptional());
}

Mono<Number> testMonoCast() {
Expand Down

0 comments on commit 1c930ba

Please sign in to comment.