Stream of a reverse list
Remi Forax
forax at univ-mlv.fr
Mon Jul 15 11:30:17 PDT 2013
On 07/15/2013 08:19 PM, Dan Smith wrote:
> On Jul 15, 2013, at 7:53 AM, Remi Forax <forax at univ-mlv.fr> wrote:
>
>> On 07/15/2013 03:36 PM, Brian Goetz wrote:
>>> We did consider such a stream op and triaged it away as bring too niche. It also requires a full barrier to get the first element. And for infinite streams obviously blows up.
>>>
>>> Given that it always requires a full barrier, toArray seems the best way to go.
>>>
>>> Sent from my iPad
>> We reject having a method reverse() on Stream but not the fact that one can create a Stream that will iterate over the list in a backward way.
>> But perhaps, it's better to have a method of List named reverseList() that return a reverse view of the list
>> and calls stream() on it.
> Has to be prioritized, of course, but I think 'List.reverseStream' is in principle a good suggestion.
reverseStream will also call for a reverseParallelStream(),
I think I prefer a reverseList (and reverseIterator like in Deque)
declared on List.
> Looks a lot like the idea of having different methods on CharSequence to get char-based and int-based views of the same data. In this case, we're getting front-to-back and back-to-front views of the List.
>
> Collection is _not_ a good place to put a method like this, because Collections are not designed to support reverse-order traversal.
I agree.
> Lists are (see ListIterator). As are Deques (see Deque.desendingIterator). (I was surprised, actually, to not find a similar List.reverseIterator method
Deque was not introduce in 1.2 but later, in 1.6 I think.
> -- I guess the intended idiom is to call 'list.iterator(list.size())' and then iterate with 'ListIterator.previous'.)
Yes, if the list is not backed by an array.
>
> —Dan
Rémi
More information about the lambda-libs-spec-experts
mailing list