Arrays.parallel vs Arrays.asStream
daniel.smith at oracle.com
Wed Sep 5 14:58:27 PDT 2012
On Aug 31, 2012, at 10:14 AM, Aleksey Shipilev <aleksey.shipilev at oracle.com> wrote:
> I found the inconsistency in API for Arrays in it2 branch:
> Arrays.asList(T... t) // returns List<T>
> Arrays.parallel(T t) // returns Stream<T> (parallel)
> Arrays.asStream(T... t) // returns Stream<T> (sequential?)
> Two basic options:
> - rename parallel() to asParallel() or asParallelStream().
> - rename asStream() to sequential()
> Also can be the mixture of both.
I wouldn't put 'asList' in the same category as 'parallel'/'asStream'. 'asList' produces an equivalent to the array, wrapped in a different API. The other two produce streams, which in it2 are more like cursors or iterators -- it is an object that is connected to an array, but it's not an equivalent of the array under a different API. Each operation are more like a "get" than an "as".
With that in mind, my opinion is that something like your second option -- eliminating the 'as' part of the name -- seems most appropriate.
More information about the lambda-dev