Skip to content

Commit

Permalink
Suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
rickie committed Feb 20, 2024
1 parent 3b28d4c commit bd3b01e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,21 @@ Flux<T> after(Flux<? extends Iterable<T>> flux, int prefetch) {
}
}

/**
* Don't unnecessarily convert {@link Collection} to {@link Stream} before creating {@link Flux}.
*/
static final class FluxFromIterable<T> {
@BeforeTemplate
Flux<T> before(Collection<T> c) {
return Flux.fromStream(c.stream());
}

@AfterTemplate
Flux<T> after(Collection<T> c) {
return Flux.fromIterable(c);
}
}

/**
* Prefer {@link Flux#count()} followed by a conversion from {@code long} to {@code int} over
* collecting into a list and counting its elements.
Expand Down Expand Up @@ -1900,19 +1915,4 @@ Duration after(StepVerifier.LastStep step, Duration duration) {
return step.verifyTimeout(duration);
}
}

/**
* Don't unnecessarily convert {@link Collection} to {@link Stream} before creating {@link Flux}.
*/
static final class FluxFromIterable<T> {
@BeforeTemplate
Flux<T> before(Collection<T> c) {
return Flux.fromStream(c.stream());
}

@AfterTemplate
Flux<T> after(Collection<T> c) {
return Flux.fromIterable(c);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,10 @@ ImmutableSet<Flux<String>> testConcatMapIterableIdentityWithPrefetch() {
Flux.just(ImmutableList.of("bar")).concatMap(Flux::fromIterable, 2));
}

Flux<String> testFluxFromIterable() {
return Flux.fromStream(ImmutableList.of("foo").stream());
}

ImmutableSet<Mono<Integer>> testFluxCountMapMathToIntExact() {
return ImmutableSet.of(
Flux.just(1).collect(toImmutableList()).map(Collection::size),
Expand Down Expand Up @@ -646,8 +650,4 @@ Duration testStepVerifierLastStepVerifyErrorMessage() {
Duration testStepVerifierLastStepVerifyTimeout() {
return Mono.empty().as(StepVerifier::create).expectTimeout(Duration.ZERO).verify();
}

Flux<String> testFluxFromIterable() {
return Flux.fromStream(ImmutableList.of("foo").stream());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,10 @@ ImmutableSet<Flux<String>> testConcatMapIterableIdentityWithPrefetch() {
Flux.just(ImmutableList.of("bar")).concatMapIterable(identity(), 2));
}

Flux<String> testFluxFromIterable() {
return Flux.fromIterable(ImmutableList.of("foo"));
}

ImmutableSet<Mono<Integer>> testFluxCountMapMathToIntExact() {
return ImmutableSet.of(
Flux.just(1).count().map(Math::toIntExact),
Expand Down Expand Up @@ -627,8 +631,4 @@ Duration testStepVerifierLastStepVerifyErrorMessage() {
Duration testStepVerifierLastStepVerifyTimeout() {
return Mono.empty().as(StepVerifier::create).verifyTimeout(Duration.ZERO);
}

Flux<String> testFluxFromIterable() {
return Flux.fromIterable(ImmutableList.of("foo"));
}
}

0 comments on commit bd3b01e

Please sign in to comment.