Skip to content

Commit

Permalink
Prefer Streams#concat over contrived alternative
Browse files Browse the repository at this point in the history
  • Loading branch information
mlrprananta authored and Stephan202 committed May 11, 2023
1 parent 4e5f0a5 commit 573c7fc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.errorprone.refaster.annotation.MayOptionallyUse;
import com.google.errorprone.refaster.annotation.NotMatches;
import com.google.errorprone.refaster.annotation.Placeholder;
import com.google.errorprone.refaster.annotation.Repeated;
import com.google.errorprone.refaster.annotation.UseImportPolicy;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -635,4 +636,16 @@ Stream<T> after(Stream<T> s1, Stream<T> s2) {
return Stream.concat(s1, s2);
}
}

static final class StreamsConcat<T> {
@BeforeTemplate
Stream<T> before(@Repeated Stream<T> stream) {
return Stream.of(Refaster.asVarargs(stream)).flatMap(Function.identity());
}

@AfterTemplate
Stream<T> after(@Repeated Stream<T> stream) {
return Streams.concat(Refaster.asVarargs(stream));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,9 @@ ImmutableSet<Integer> testStreamFlatMapCollect() {
Stream<Integer> testStreamConcat() {
return Stream.of(Stream.of(1), Stream.of(2)).flatMap(Function.identity());
}

Stream<Integer> testStreamsConcat() {
return Stream.of(Stream.of(1), Stream.of(2), Stream.of(3), Stream.of(4))
.flatMap(Function.identity());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,8 @@ ImmutableSet<Integer> testStreamFlatMapCollect() {
Stream<Integer> testStreamConcat() {
return Stream.concat(Stream.of(1), Stream.of(2));
}

Stream<Integer> testStreamsConcat() {
return Streams.concat(Stream.of(1), Stream.of(2), Stream.of(3), Stream.of(4));
}
}

0 comments on commit 573c7fc

Please sign in to comment.