public static DoubleStream merge(final DoubleIterator a, final DoubleIterator b, final DoubleBiFunction<Nth> nextSelector) {
        return new IteratorDoubleStream(new DoubleIteratorEx() {
            private double nextA = 0;
            private double nextB = 0;
            private boolean hasNextA = false;
            private boolean hasNextB = false;

            @Override
            public boolean hasNext() {
                return a.hasNext() || b.hasNext() || hasNextA || hasNextB;
            }

            @Override
            public double nextDouble() {
                if (hasNextA) {
                    if (b.hasNext()) {
                        if (nextSelector.apply(nextA, (nextB = b.nextDouble())) == Nth.FIRST) {
                            hasNextA = false;
                            hasNextB = true;
                            return nextA;
                        } else {
                            return nextB;
                        }
                    } else {
                        hasNextA = false;
                        return nextA;
                    }
                } else if (hasNextB) {
                    if (a.hasNext()) {
                        if (nextSelector.apply((nextA = a.nextDouble()), nextB) == Nth.FIRST) {
                            return nextA;
                        } else {
                            hasNextA = true;
                            hasNextB = false;
                            return nextB;
                        }
                    } else {
                        hasNextB = false;
                        return nextB;
                    }
                } else if (a.hasNext()) {
                    if (b.hasNext()) {
                        if (nextSelector.apply((nextA = a.nextDouble()), (nextB = b.nextDouble())) == Nth.FIRST) {
                            hasNextB = true;
                            return nextA;
                        } else {
                            hasNextA = true;
                            return nextB;
                        }
                    } else {
                        return a.nextDouble();
                    }
                } else if (b.hasNext()) {
                    return b.nextDouble();
                } else {
                    throw new NoSuchElementException();
                }
            }
        });
    }
public static DoubleStream merge ( final DoubleIterator a , final DoubleIterator b , final DoubleBiFunction < Nth > nextSelector ) { return new IteratorDoubleStream ( new DoubleIteratorEx ( ) { private double nextA = 0 ; private double nextB = 0 ; private boolean hasNextA = false ; private boolean hasNextB = false ; @ Override public boolean hasNext ( ) { return a . hasNext ( ) || b . hasNext ( ) || hasNextA || hasNextB ; } @ Override public double nextDouble ( ) { if ( hasNextA ) { if ( b . hasNext ( ) ) { if ( nextSelector . apply ( nextA , ( nextB = b . nextDouble ( ) ) ) == Nth . FIRST ) { hasNextA = false ; hasNextB = true ; return nextA ; } else { return nextB ; } } else { hasNextA = false ; return nextA ; } } else if ( hasNextB ) { if ( a . hasNext ( ) ) { if ( nextSelector . apply ( ( nextA = a . nextDouble ( ) ) , nextB ) == Nth . FIRST ) { return nextA ; } else { hasNextA = true ; hasNextB = false ; return nextB ; } } else { hasNextB = false ; return nextB ; } } else if ( a . hasNext ( ) ) { if ( b . hasNext ( ) ) { if ( nextSelector . apply ( ( nextA = a . nextDouble ( ) ) , ( nextB = b . nextDouble ( ) ) ) == Nth . FIRST ) { hasNextB = true ; return nextA ; } else { hasNextA = true ; return nextB ; } } else { return a . nextDouble ( ) ; } } else if ( b . hasNext ( ) ) { return b . nextDouble ( ) ; } else { throw new NoSuchElementException ( ) ; } } } ) ; }
@param a
@param b
@param nextSelector first parameter is selected if <code>Nth.FIRST</code> is returned, otherwise the second parameter is selected.
@return