@ SuppressWarnings ( "unchecked" ) public final static < T > Tuple4 < Stream < T > , Stream < T > , Stream < T > , Stream < T > > quadruplicate ( final Stream < T > stream ) { final Stream < Stream < T > > its = Streams . toBufferingCopier ( stream . iterator ( ) , 4 ) . stream ( ) . map ( it -> Streams . stream ( it ) ) ; final Iterator < Stream < T > > it = its . iterator ( ) ; return new Tuple4 ( it . next ( ) , it . next ( ) , it . next ( ) , it . next ( ) ) ; }
Makes four copies of a Stream Buffers intermediate values leaders may change positions so a limit can be safely applied to the leading stream . Not thread - safe .