Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

may supply some method Stream.concat, Stream.append, Stream.prepend #185

Closed
wjtxyz opened this issue Oct 20, 2020 · 1 comment · Fixed by #187
Closed

may supply some method Stream.concat, Stream.append, Stream.prepend #185

wjtxyz opened this issue Oct 20, 2020 · 1 comment · Fixed by #187

Comments

@wjtxyz
Copy link

wjtxyz commented Oct 20, 2020

simplify the stream concatenation syntax

static <T> Stream<T> concat2(final Stream<T> ...streams){        
    return Stream.of(streams).flatMap(UnaryOperator.Util.identity());
}

Stream<T> append(T t){
   return Stream.concat(this, Stream.of(t));  
}

Stream<T> prepend(T t){
   return Stream.concat(Stream.of(t), this);
}
@aNNiMON
Copy link
Owner

aNNiMON commented Oct 21, 2020

Concatenating more than two streams is a good idea. I've start implementing this on #187
In order not to break compatibility (and to avoid concat2 naming), I've created a method

public static <T> Stream<T> concat(
            Stream<? extends T> stream1,
            Stream<? extends T> stream2,
            Stream<? extends T>... rest)

but i think it would be better to replace this with simple

public static <T> Stream<T> concat(
            List<Stream<? extends T>> streams)

So, it will be possible to call the method by passing a dynamically generated list of streams

List<Stream<Integer>> streams = Stream.range(1, 5)
        .flatMap(count -> Stream.range(0, count))
        .toList();
Stream.concat(streams).map(...)

or by specifying all streams statically:

Stream.concat(Arrays.asList(stream1, stream2, stream3)).map(...)

@aNNiMON aNNiMON linked a pull request Dec 8, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants