private static < T > Stream < T > generateStream ( T seed , Predicate < ? super T > hasNext , UnaryOperator < T > next ) { final Spliterator < T > spliterator = Spliterators . spliteratorUnknownSize ( new Iterator < T > ( ) { private T last = seed ; @ Override public boolean hasNext ( ) { return hasNext . test ( last ) ; } @ Override public T next ( ) { final T current = last ; last = next . apply ( last ) ; return current ; } } , Spliterator . ORDERED ) ; return StreamSupport . stream ( spliterator , false ) ; }
remove on Java 9 and replace with Stream . iterate