Skip to content

Instantly share code, notes, and snippets.

@kacper-kuczek
Forked from edalorzo/StreamConcat.java
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save kacper-kuczek/e7852ef6a6ee4442fec9 to your computer and use it in GitHub Desktop.

Select an option

Save kacper-kuczek/e7852ef6a6ee4442fec9 to your computer and use it in GitHub Desktop.
import java.util.stream.Stream;
import org.junit.Test;
import static java.util.function.Function.identity;
public class StreamConcat {
@SafeVarargs
public static <T> Stream<T> concatenate(Stream<? extends T>... streams) {
return Stream.of(streams).reduce(Stream.empty(), Stream::concat).map(identity());
}
@Test
public void learnAboutConcatenate() {
Stream<CharSequence> res = concatenate(
Stream.of("One"),
Stream.of(new StringBuffer("Two")),
Stream.of(new StringBuilder("Three"))
);
res.forEach(System.out::println);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment