Stream.limit() - puzzler/bug/feature

Dmitry Bessonov dmitry.bessonov at oracle.com
Thu Nov 15 00:32:49 PST 2012


Hello,

While playing with method Sream.limit(int) using a mini-code like

         final Stream<Integer> s = Arrays.asStream(1, 2, 3, 4, 5);
         final Stream<Integer> to3 = s.limit(3);
         final Stream<Integer> to4 = s.limit(4);

have to admit that there's no unambiguous answer
to the question of contents  of streams "to3" and "to4".
It depends on which of the streams is consumed first.

Might situations (and mis-usage?) like this above
be a trap for novice users
that should be well described?

Dmitry



More information about the lambda-dev mailing list