On Wed, 27 Nov 2024 16:01:53 GMT, Michel Charpentier <d...@openjdk.org> wrote:

>> Viktor Klang has updated the pull request incrementally with one additional 
>> commit since the last revision:
>> 
>>   Addressing review feedback
>
> I just noticed this improved performance in Java 23. However, it still 
> doesn't fit my needs because this doesn't work:
> 
> 
> Stream.of(1)
> .flatMap(c -> Stream.generate(() -> 1).flatMap(x -> Stream.generate(() -> x)))
> .iterator()
> .next()
> 
> 
> Should it work? And how else can one use some stream elements in a 
> non-terminal way?
> (See my forum question here: 
> https://forums.oracle.com/ords/apexds/post/laziness-of-stream-iterators-3439.)

@charpov `Stream::iterator()` and `Stream::spliterator()` both consume the 
stream when they are invoked, so they are terminal operations. Converting a 
push-style stream (which the reference implementation of Stream is) to a 
pull-style stream (which Spliterator and Iterator are) has limitations—as you 
discovered. In the future, questions like these are likely better submitted to 
[core-libs-dev](https://mail.openjdk.org/pipermail/core-libs-dev/)

-------------

PR Comment: https://git.openjdk.org/jdk/pull/18625#issuecomment-2531340205

Reply via email to