public Optional < T > foldRight ( BinaryOperator < T > accumulator ) { return toListAndThen ( list -> { if ( list . isEmpty ( ) ) return Optional . empty ( ) ; int i = list . size ( ) - 1 ; T result = list . get ( i -- ) ; for ( ; i >= 0 ; i -- ) result = accumulator . apply ( list . get ( i ) , result ) ; return Optional . of ( result ) ; } ) ; }
Folds the elements of this stream using the provided accumulation function going right to left .