public StreamEx < List < T > > groupRuns ( BiPredicate < ? super T , ? super T > sameGroup ) { return collapseInternal ( sameGroup , Collections :: singletonList , ( acc , t ) -> { if ( ! ( acc instanceof ArrayList ) ) { T old = acc . get ( 0 ) ; acc = new ArrayList <> ( ) ; acc . add ( old ) ; } acc . add ( t ) ; return acc ; } , ( acc1 , acc2 ) -> { if ( ! ( acc1 instanceof ArrayList ) ) { T old = acc1 . get ( 0 ) ; acc1 = new ArrayList <> ( ) ; acc1 . add ( old ) ; } acc1 . addAll ( acc2 ) ; return acc1 ; } ) ; }
Returns a stream consisting of lists of elements of this stream where adjacent elements are grouped according to supplied predicate .