-
Notifications
You must be signed in to change notification settings - Fork 39
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 FluxFromStreamSupplier
Refaster rule
#1261
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -41,6 +41,7 @@ | |||||||||
import java.util.function.Predicate; | ||||||||||
import java.util.function.Supplier; | ||||||||||
import java.util.stream.Collector; | ||||||||||
import java.util.stream.Stream; | ||||||||||
import org.jspecify.annotations.Nullable; | ||||||||||
import org.reactivestreams.Publisher; | ||||||||||
import reactor.core.publisher.Flux; | ||||||||||
|
@@ -1204,10 +1205,17 @@ Flux<T> after(Flux<? extends Iterable<T>> flux, int prefetch) { | |||||||||
} | ||||||||||
|
||||||||||
/** Prefer {@link Flux#fromIterable(Iterable)} over less efficient alternatives. */ | ||||||||||
// XXX: Once the `FluxFromStreamSupplier` rule is constrained using | ||||||||||
// `@NotMatches(IsIdentityOperation.class)`, this rule should also cover | ||||||||||
// `Flux.fromStream(collection.stream())`. | ||||||||||
static final class FluxFromIterable<T> { | ||||||||||
// XXX: Once the `MethodReferenceUsage` check is generally enabled, drop the second | ||||||||||
// `Refaster.anyOf` variant. | ||||||||||
@BeforeTemplate | ||||||||||
Flux<T> before(Collection<T> collection) { | ||||||||||
return Flux.fromStream(collection.stream()); | ||||||||||
return Flux.fromStream( | ||||||||||
Refaster.<Supplier<Stream<? extends T>>>anyOf( | ||||||||||
collection::stream, () -> collection.stream())); | ||||||||||
} | ||||||||||
|
||||||||||
@AfterTemplate | ||||||||||
|
@@ -1913,7 +1921,7 @@ Duration after(StepVerifier.LastStep step, Duration duration) { | |||||||||
|
||||||||||
/** | ||||||||||
* Prefer {@link Mono#fromFuture(Supplier)} over {@link Mono#fromFuture(CompletableFuture)}, as | ||||||||||
* the former may defer initiation of the asynchornous computation until subscription. | ||||||||||
* the former may defer initiation of the asynchronous computation until subscription. | ||||||||||
*/ | ||||||||||
static final class MonoFromFutureSupplier<T> { | ||||||||||
// XXX: Constrain the `future` parameter using `@NotMatches(IsIdentityOperation.class)` once | ||||||||||
|
@@ -1932,7 +1940,7 @@ Mono<T> after(CompletableFuture<T> future) { | |||||||||
/** | ||||||||||
* Prefer {@link Mono#fromFuture(Supplier, boolean)} over {@link | ||||||||||
* Mono#fromFuture(CompletableFuture, boolean)}, as the former may defer initiation of the | ||||||||||
* asynchornous computation until subscription. | ||||||||||
* asynchronous computation until subscription. | ||||||||||
*/ | ||||||||||
static final class MonoFromFutureSupplierBoolean<T> { | ||||||||||
// XXX: Constrain the `future` parameter using `@NotMatches(IsIdentityOperation.class)` once | ||||||||||
|
@@ -1947,4 +1955,23 @@ Mono<T> after(CompletableFuture<T> future, boolean suppressCancel) { | |||||||||
return Mono.fromFuture(() -> future, suppressCancel); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Prefer {@link Flux#fromStream(Supplier)} over {@link Flux#fromStream(Stream)}, as the former | ||||||||||
* yields a {@link Flux} that is more likely to behave as expected when subscribed to more than | ||||||||||
* once. | ||||||||||
*/ | ||||||||||
static final class FluxFromStreamSupplier<T> { | ||||||||||
// XXX: Constrain the `stream` parameter using `@NotMatches(IsIdentityOperation.class)` once | ||||||||||
// `IsIdentityOperation` no longer matches nullary method invocations. | ||||||||||
@BeforeTemplate | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Is this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is 👍 |
||||||||||
Flux<T> before(Stream<T> stream) { | ||||||||||
return Flux.fromStream(stream); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This triggers an interaction with |
||||||||||
} | ||||||||||
|
||||||||||
@AfterTemplate | ||||||||||
Flux<T> after(Stream<T> stream) { | ||||||||||
return Flux.fromStream(() -> stream); | ||||||||||
} | ||||||||||
} | ||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one; should also be fixed below.