Stream constructors for stream(Iterator) in StreamSupport?

Tim Peierls tim at peierls.net
Sat Apr 13 13:57:20 PDT 2013


On Sat, Apr 13, 2013 at 3:25 PM, Brian Goetz <brian.goetz at oracle.com> wrote:

> There are lots of ways to make a stream, and some are better than others.
>  ...
>
> Best way is to get one from your data source directly (e.g.,
> ArrayList.stream()).  ...
> The next best way is via one of the factories in Streams -- things like
> intRange, iterate, generate. ...
> The next best way is via a Spliterator that properly declares its
> properties, is SIZED, SUBSIZED, and has a good trySplit implementation.
> We then slide down the scale of spliterator quality; ...
> We then come to the bottom of the barrel, iterators.  ...
> So, while Iterator to Stream is still a fine last resort, putting it in
> Streams will likely have the unfortunate effect of guiding users to the
> worst way of making a stream, without fully understanding the tradeoffs.


That's a great taxonomy of ways to make a stream, but the division of
static factory methods into Streams and StreamSupport wasn't, as I
understood it, along those lines. It was about keeping concepts that most
users aren't going to want to mess with (i.e., Spliterator) out of their
line of sight.

If all you have is an Iterator, you don't want have to go down into the
basement to get something that turns it into a Stream. Put those tradeoffs
on the packaging but leave the package in the kitchen.

--tim


More information about the lambda-libs-spec-observers mailing list