Expected behavior of a Streams.cycled() instance - found issues and questions

Paul Sandoz paul.sandoz at oracle.com
Tue Oct 23 12:07:57 PDT 2012


On Oct 23, 2012, at 8:02 PM, Olexandr Demura <oleksander.demura at gmail.com> wrote:

> flatMap(Block<R> sink, T element).iterator() supposed to return Iterator<R>
> of outputs you produce from elements and put into sink.
> You put none, so next() hangs till there is something in the sink
> because original stream never ends.
> 

Right, it's looping in the hasNext  of the FlatMapOp iterator:

            @Override
            public boolean hasNext() {
                while (true) {
                    if (currentMapped == null) {
                        if (!source.hasNext()) {
                            return false;
                        } else {
                            buffer.clear();
                            mapper.flatMapInto(bufferTarget, source.next());
                            currentMapped = buffer.iterator();
                        }
                    } else {
                        if (currentMapped.hasNext()) {
                            return true;
                        } else {
                            currentMapped = null;
                        }
                    }
                }
            }

Paul.

> 2012/10/23 Dmitry Bessonov <dmitry.bessonov at oracle.com>:
>>  2) Getting next element of a flatMap of a cycled stream leads to hanging:
>>     Streams.cycle(Arrays.asList(1, 2, 3)).flatMap((Block<Object> sink,
>> Integer element) -> {}).iterator().next();
> 



More information about the lambda-dev mailing list