Skip to content

Commit

Permalink
Introduce FluxFromIterable Refaster rule (#1047)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkvbok authored Feb 22, 2024
1 parent 41e4211 commit ded0a48
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,19 @@ Flux<T> after(Flux<? extends Iterable<T>> flux, int prefetch) {
}
}

/** Prefer {@link Flux#fromIterable(Iterable)} over less efficient alternatives. */
static final class FluxFromIterable<T> {
@BeforeTemplate
Flux<T> before(Collection<T> collection) {
return Flux.fromStream(collection.stream());
}

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

/**
* 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
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
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

0 comments on commit ded0a48

Please sign in to comment.