Stream of a reverse list

David M. Lloyd david.lloyd at redhat.com
Mon Jul 22 15:02:31 PDT 2013


Sure.  My point though (in case it wasn't clear) was that it's better to 
have a general reverse list view method than it is to have a 
reverseStream method on List (and possibly a host of other 
specific-purpose reversal methods in the vein of Deque's descending 
iterator).  If that means the whole thing is put off because it sort of 
implies a more general effort, well, that's a judgment call I don't 
necessarily agree with (i.e. you draw that line here, I draw it there) 
but I respect it.

On 07/16/2013 03:31 PM, Brian Goetz wrote:
> All lists have a reverse order because they are finite.  Not all streams have a reverse order.
>
> More generally, we probably want more "view" combinators on collections, for things like concat, reverse, or merge without paying the price of a full copy.  That's a story for another day.
>
>
> Sent from my iPad
>
> On Jul 16, 2013, at 3:59 PM, Dan Smith <daniel.smith at oracle.com> wrote:
>
>> On Jul 15, 2013, at 1:01 PM, David M. Lloyd <david.lloyd at redhat.com> wrote:
>>
>>> 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).
>>
>> Sort of a conglomeration of you mentioning Collections and Brian talking about a Stream method.  But, yeah, I did realize when reading carefully that you were talking about a static method operating on Lists.
>>
>> The idea is it's fairly painless to "streamify" existing concepts, like reverse List and Deque iteration; much more expensive (and perhaps ill-advised) to create new concepts, like every Stream having a reverse order.
>>
>> —Dan


-- 
- DML


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