Skip to content

Commit

Permalink
Merge pull request #362 from gdgib/G2-1508-NullStreams
Browse files Browse the repository at this point in the history
G2-1508 Filter out null streams during concatenation
  • Loading branch information
gdgib authored Jan 18, 2024
2 parents 97f5ac7 + 3e0d447 commit 2355b26
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class HStream {
@SafeVarargs
public static <T> Stream<T> concat(Stream<? extends T>... streams) {
return Arrays.stream(streams).reduce(Stream::concat).get().map(t -> t);
return Arrays.stream(streams).filter(Objects::nonNull).reduce(Stream::concat).get().map(t -> t);
}

public static <T> T findOne(Stream<? extends T> stream) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ public void productTyped() {
final List<String> actual = HStream.product((String a, Integer b) -> a + b, () -> Stream.of("A", "B"), () -> Stream.of(0, 1)).collect(Collectors.toList());
Assert.assertEquals(new ArrayList<>(HCollection.asList("A0", "A1", "B0", "B1")), actual);
}

@Test
public void ofNull() {
Assert.assertEquals(HCollection.asList(0, 1), HStream.concat(null, Stream.of(0, 1)).collect(Collectors.toList()));
}
}

0 comments on commit 2355b26

Please sign in to comment.