@ SuppressWarnings ( "unchecked" ) public < U > List < U > scanRight ( U seed , BiFunction < ? super T , U , U > accumulator ) { return toListAndThen ( list -> { // Reusing the list for different object type as it will save memory List < U > result = ( List < U > ) list ; result . add ( seed ) ; for ( int i = result . size ( ) - 2 ; i >= 0 ; i -- ) { result . set ( i , accumulator . apply ( ( T ) result . get ( i ) , result . get ( i + 1 ) ) ) ; } return result ; } ) ; }
Produces a list containing cumulative results of applying the accumulation function going right to left using given seed value .