easier work with collections: default Stream.toList?
paul.sandoz at oracle.com
Mon Sep 30 01:25:51 PDT 2013
On Sep 29, 2013, at 6:31 PM, Paul Benedict <pbenedict at apache.org> wrote:
> I think, at one time, someone recommended toArray() and Brain said this
> would obviously fail with infinite streams.
It would, although i don't recall that being discussed in reference to not including toArray. It's no different to collect(toList()) failing either, or any other operation that may not terminate due to infinite input.
> Wouldn't toList() bring the
> same consequences?
The main reasons for resisting Stream.toList etc are:
1) It ties streams to the existing collections API; and
2) If we add a few then people may likely want more.
i.e. pollution and not enough pollution respectively :-)
I like the purity of streams.
However, I find the arguments are persuasive for adding a few, say for List<T> and Map<K, List<T>> for common cases of toList and groupingBy. New users need not run into Collector immediately and for more experienced users it's just more concise.
More information about the lambda-dev