public static < T > Stream < List < T > > aggregate ( Stream < T > source , int size ) { if ( size <= 0 ) throw new IllegalArgumentException ( "Positive size expected, was: " + size ) ; return StreamSupport . stream ( new AggregatingSpliterator <> ( source . spliterator ( ) , ( a , e ) -> a . size ( ) < size ) , false ) . onClose ( source :: close ) ; }
Aggregates items from source stream into list of items with fixed size