Skip to content

Commit

Permalink
Introduce MonoSingleOptional Refaster rule
Browse files Browse the repository at this point in the history
  • Loading branch information
rickie committed Feb 20, 2023
1 parent 208659d commit 5ee0703
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,19 @@ Mono<Optional<T>> after(Mono<T> mono) {
}
}

/** Prefer {@link Mono#singleOptional()} over more contrived alternatives. */
static final class MonoSingleOptional<T> {
@BeforeTemplate
Mono<Optional<T>> before(Mono<T> mono) {
return mono.flux().collect(toOptional());
}

@AfterTemplate
Mono<Optional<T>> after(Mono<T> mono) {
return mono.singleOptional();
}
}

/** Prefer {@link Mono#cast(Class)} over {@link Mono#map(Function)} with a cast. */
static final class MonoCast<T, S> {
@BeforeTemplate
Expand Down

0 comments on commit 5ee0703

Please sign in to comment.