Zipping Steams...

Paul Sandoz paul.sandoz at oracle.com
Tue Jan 14 00:42:19 PST 2014


On Jan 14, 2014, at 1:00 AM, Brent Walker <brenthwalker at gmail.com> wrote:

> Ah yes the curse of the megamorphic.  Ok, I went back to the consumer style as you had it but with only 1 member variable (instead of two).  After the first tryAdvance() you can remember the left value in a local variable so the accept function just becomes:
> 
>     @Override
>     public void accept(final Object x) {
>       mCache = x;
>     }
> 
> and tryAdvance():
> 
>     @Override
>     @SuppressWarnings("unchecked")
>     public boolean tryAdvance(Consumer<? super W> action) {
>       if (mLeftSpliter.tryAdvance(this)) {
>         final T leftElem = (T) mCache;
> 
>         if (mRightSpliter.tryAdvance(this)) {
>           final U rightElem = (U) mCache;
> 
>           action.accept(mZipper.apply(leftElem, rightElem));
>           return true;
>         }
>       }
>       return false;
>     }
> 

Yes, that is better.

Paul.



More information about the lambda-dev mailing list