@NotNull
    public Optional<T> reduce(@NotNull BiFunction<T, T, T> accumulator) {
        boolean foundAny = false;
        T result = null;
        while (iterator.hasNext()) {
            final T value = iterator.next();
            if (!foundAny) {
                foundAny = true;
                result = value;
            } else {
                result = accumulator.apply(result, value);
            }
        }
        return foundAny ? Optional.of(result) : Optional.<T>empty();
    }
@ NotNull public Optional < T > reduce ( @ NotNull BiFunction < T , T , T > accumulator ) { boolean foundAny = false ; T result = null ; while ( iterator . hasNext ( ) ) { final T value = iterator . next ( ) ; if ( ! foundAny ) { foundAny = true ; result = value ; } else { result = accumulator . apply ( result , value ) ; } } return foundAny ? Optional . of ( result ) : Optional . < T > empty ( ) ; }
Reduces the elements using provided associative accumulation function.

<p>This is a terminal operation.

@param accumulator  the accumulation function
@return the result of the reduction
@see #reduce(java.lang.Object, com.annimon.stream.function.BiFunction)