public Optional < T > maxByInt ( ToIntFunction < ? super T > keyExtractor ) { return Box . asOptional ( reduce ( null , ( ObjIntBox < T > acc , T t ) -> { int val = keyExtractor . applyAsInt ( t ) ; if ( acc == null ) return new ObjIntBox <> ( t , val ) ; if ( val > acc . b ) { acc . b = val ; acc . a = t ; } return acc ; } , ( ObjIntBox < T > acc1 , ObjIntBox < T > acc2 ) -> ( acc1 == null || acc2 != null && acc1 . b < acc2 . b ) ? acc2 : acc1 ) ) ; }
Returns the maximum element of this stream according to the int values extracted by provided function . This is a special case of a reduction .