Skip to content

Commit

Permalink
ANS-1289 Extend to concatMap
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastien Diederichs committed Oct 5, 2022
1 parent 6cf3c93 commit 990b11c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,19 +273,39 @@ Flux<S> after(Flux<T> flux) {
}

/**
* Prefer {@link Flux#flatMapIterable(Function)} (Class)} over {@link Flux#flatMap(Function)} with
* Prefer {@link Flux#concatMapIterable(Function)} over {@link Flux#concatMap(Function)} with
* {@link Flux#fromIterable(Iterable)}.
*/
static final class FluxFlatMapIterable<S> {
static final class FluxConcatMapFromIterable<S> {
@BeforeTemplate
Flux<S> before(Flux<? extends Iterable<S>> flux) {
return flux.flatMap(list -> Flux.fromIterable(list));
return Refaster.anyOf(
flux.concatMap(list -> Flux.fromIterable(list)), flux.concatMap(Flux::fromIterable));
}

@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
Flux<S> after(Flux<? extends Iterable<S>> flux) {
return flux.flatMapIterable(identity());
return flux.concatMapIterable(identity());
}
}

/**
* Prefer {@link Flux#flatMapIterable(Function, int)} over {@link Flux#flatMap(Function, int)}
* with {@link Flux#fromIterable(Iterable)}.
*/
static final class FluxFlatMapFromIterable<S> {
@BeforeTemplate
Flux<S> before(Flux<? extends Iterable<S>> flux, int concurrency) {
return Refaster.anyOf(
flux.flatMap(list -> Flux.fromIterable(list), concurrency),
flux.flatMap(Flux::fromIterable, concurrency));
}

@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
Flux<S> after(Flux<? extends Iterable<S>> flux, int concurrency) {
return flux.flatMapIterable(identity(), concurrency);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,16 @@ Flux<Number> testFluxCast() {
return Flux.just(1).map(Number.class::cast);
}

Flux<String> testFluxFlatMapIterable() {
return Flux.just(ImmutableList.of("1")).flatMap(list -> Flux.fromIterable(list));
ImmutableSet<Flux<String>> testFluxConcatMapFromIterable() {
return ImmutableSet.of(
Flux.just(ImmutableList.of("1")).concatMap(list -> Flux.fromIterable(list)),
Flux.just(ImmutableList.of("1")).concatMap(Flux::fromIterable));
}

ImmutableSet<Flux<String>> testFluxFlatMapFromIterable() {
return ImmutableSet.of(
Flux.just(ImmutableList.of("1")).flatMap(list -> Flux.fromIterable(list), 1),
Flux.just(ImmutableList.of("1")).flatMap(Flux::fromIterable, 2));
}

ImmutableSet<PublisherProbe<Void>> testPublisherProbeEmpty() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,16 @@ Flux<Number> testFluxCast() {
return Flux.just(1).cast(Number.class);
}

Flux<String> testFluxFlatMapIterable() {
return Flux.just(ImmutableList.of("1")).flatMapIterable(identity());
ImmutableSet<Flux<String>> testFluxConcatMapFromIterable() {
return ImmutableSet.of(
Flux.just(ImmutableList.of("1")).concatMapIterable(identity()),
Flux.just(ImmutableList.of("1")).concatMapIterable(identity()));
}

ImmutableSet<Flux<String>> testFluxFlatMapFromIterable() {
return ImmutableSet.of(
Flux.just(ImmutableList.of("1")).flatMapIterable(identity(), 1),
Flux.just(ImmutableList.of("1")).flatMapIterable(identity(), 2));
}

ImmutableSet<PublisherProbe<Void>> testPublisherProbeEmpty() {
Expand Down

0 comments on commit 990b11c

Please sign in to comment.