public final static < T > Stream < T > scanLeft ( final Stream < T > stream , final Monoid < T > monoid ) { final Iterator < T > it = stream . iterator ( ) ; return Streams . stream ( new Iterator < T > ( ) { boolean init = false ; T next = monoid . zero ( ) ; @ Override public boolean hasNext ( ) { if ( ! init ) return true ; return it . hasNext ( ) ; } @ Override public T next ( ) { if ( ! init ) { init = true ; return monoid . zero ( ) ; } return next = monoid . apply ( next , it . next ( ) ) ; } } ) ; }
Scan left using supplied Monoid