Stream of a reverse list
David M. Lloyd
david.lloyd at redhat.com
Mon Jul 15 08:38:13 PDT 2013
On 07/15/2013 08:53 AM, Remi Forax 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.
Perhaps a viable alternative is to add a Collections.reversedView(List)
method which presents a reverse-order view of a List, rather than
growing the List API for this specific purpose. This would be more
generally useful, if I understand the default implementation of
.stream() and .spliterator() correctly.
>
> Rémi
>
>>
>> On Jul 15, 2013, at 9:28 AM, Joe Bowbeer <joe.bowbeer at gmail.com
>> <mailto:joe.bowbeer at gmail.com>> wrote:
>>
>>> It seems like overkill to add a specific method for what is likely to
>>> be a general problem, but it's not clear to me what the best general
>>> solution is...
>>>
>>> One option is to create an IntStream of reversed indices, using
>>> iterate(), then map that to a stream of elements.
>>>
>>> Can generate() be used in this situation to generate the reversed
>>> stream directly?
>>>
>>> --Joe
>>>
>>> On Jul 15, 2013 2:41 AM, "Remi Forax" <forax at univ-mlv.fr
>>> <mailto:forax at univ-mlv.fr>> wrote:
>>>
>>> How to get a stream of a list in reverse order without actually
>>> reversing the list ?
>>>
>>> do we need a List.reverseStream() or there is another way ?
>>>
>>> Rémi
>>>
>
--
- DML
More information about the lambda-libs-spec-observers
mailing list