Getting rid of pull
Brian Goetz
brian.goetz at oracle.com
Wed Dec 19 06:05:46 PST 2012
We considered that before we ever went down the Iterator route. If
forEach were entirely internal, we would have done that in a minute.
But forEach is defined on Collection, Iterator, etc. And this would
would turn things like Collection.forEach into something that is not
really forEach.
On 12/19/2012 5:46 AM, Gernot Neppert wrote:
>
>
>
> 2012/12/19 Brian Goetz <brian.goetz at oracle.com
> <mailto:brian.goetz at oracle.com>>
>
>
>
> We can even go one step farther, and eliminate iterators completely,
> but it involves some ugliness. The ugliness involves use of an
> exception to signal from a forEach target through the forEach source
> to the initiator of the forEach to about dispensing of elements.
> (We can eliminate most of the cost of the exception by not
> gathering the stack trace, which is by far the most expensive part.)
> Then, Spliterator need not even support an iterator() method, just
> a forEach method that doesn't fall apart if you throw an exception
> through it. (Similarly, we don't expose an iterator() method, just
> a version of forEach that lets the target say "no mas" which causes
> the exception to be thrown.)
>
>
>
> Just a thought: given the name of Block's method ("accept"), wouldn't it
> fit in very nicely to simply have it return a boolean saying "OK,
> accepted, give me more" or "No thank you, I'm full"?
>
> That way you wouldn't need ugly Exceptions to indicate End Of Stream
> Traversal.
>
>
>
More information about the lambda-libs-spec-observers
mailing list