RFR: 8005051: default methods for Iterator

Remi Forax forax at univ-mlv.fr
Fri Dec 14 05:34:37 PST 2012


On 12/14/2012 02:00 PM, Paul Sandoz wrote:
> On Dec 14, 2012, at 11:54 AM, Remi Forax <forax at univ-mlv.fr> wrote:
>> We can't remove Collection.forEach without having perf issue because the stream pipeline use it.
>> Iterator.forEach can be removed but it's a pity because it's really convenient,
> And a case can be made performance wise too (there are optimal implementations in the stream code base).
>
> I have found that forEach, in general, has been very useful. Since it abstracts away the details of traversal it has enabled better re-use of code.

thinking a little bit more about what you said, for the sequential 
implementation of the pipeline, there is no reason to use Iterator.forEach,
if you can use forEach, it means that the logic can be encapsulated in a 
forEach, so the terminal op is not a short-circuited operation,
so you can write it without an iterator.

in the parallel case, it's different because the Spliterator exports 
only the data as an Iterator.

>
> Paul.

Rémi

>
>> a possble solution is to rename Iterator.forEach() to something else.
>>
>>> Please review
>>> Thanks
>>>
>> cheers,
>> Rémi
>>



More information about the lambda-dev mailing list