For the function Function<T, T> fand Stream<T> ts, which is a good (good readability, good performance) way to create a new Stream<T>one that first contains the original elements, and then the elements converted to f.
You might think this would work:
Stream.concat(ts, ts.map(f));
But this does not work and throws an exception:
java.lang.IllegalStateException: stream has already been operated upon or closed
Note: that order matters: the original elements must be first in the correct order, and then the converted elements in order of coincidence.
source
share