Stream of a reverse list

David M. Lloyd david.lloyd at redhat.com
Mon Jul 15 12:01:59 PDT 2013


On 07/15/2013 01: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.  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.  Lists are (see ListIterator).  As are Deques (see Deque.desendingIterator).  (I was surprised, actually, to not find a similar List.reverseIterator method -- I guess the intended idiom is to call 'list.iterator(list.size())' and then iterate with 'ListIterator.previous'.)

If that is directed at me... I did not suggest Collection, I suggested 
Collections, in lieu of adding a default method to List (though that's 
an option too).


-- 
- DML


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