Stream reuse in superclass

Jose jgetino at
Fri Apr 5 07:31:54 PDT 2013

I checked your suggestion

                  singleAdd(R row)

and it works fine. But on the other hand I can't understad your other

>> Actually this (peek ) won't do anything -- peek is not a terminal

I guess peek() is evaluted when the stream reaches the superclass and enters
the forEach.
I tested with peek() and everithing works as expected, the table had been
registered to the incomming rows. 
To recheck, I placed a  breakpoint on the addReceiver() method and the
debugger stops there. 

Is there anything bad in using peek() in cases like this?

-----Mensaje original-----
De: Brian Goetz [mailto:brian.goetz at] 
Enviado el: viernes, 05 de abril de 2013 15:57
Para: Jose
CC: lambda-dev at
Asunto: Re: Stream reuse in superclass

>   public void addRows(Stream<Foo> rows) {
>          rows=rows.peek(row -> row.addReceiver(this));

Actually this won't do anything -- peek is not a terminal operation.

But in your case, I think the issue is the tension between wanting to add
the rows in bulk before firing the change event, and wanting to get access
to each one as it is added.  THat's not a stream problem :) There's a simple
refactor here:

   public void bulkAdd(Stream<R> rows) {
       rows.forEach(r -> singleAdd(r));

   protected void singleAdd(R row) {

Now the subclass overrides singleAdd.

More information about the lambda-dev mailing list