tee() (original) (raw)

Tim Peierls tim at peierls.net
Thu Jan 24 12:54:03 PST 2013


On Thu, Jan 24, 2013 at 3:43 PM, Kevin Bourrillion <kevinb at google.com>wrote:

It just feels very, very strange to let the user inject a side-effect into the middle of their stream somewhere, for mysterious hidden later execution maybe.

If tee stays in -- not saying it should -- what about a special argument type:

<T> Stream<T> tee(Observer<? super T> observer);  // tee ->

observingWith ?

where

public interface Observer<T> /* does not extend Consumer/Sink/Block! */

{ void observe(T value); }

That distinction would be lost when using lambdas, but in other cases it could serve as a reminder that you can look but not touch.

Maybe have a boolean return from observe, with false meaning "no longer interested in observing". That would prevent lambda writers from accidentally using something that looks like a Consumer/Sink/Block.

--tim



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