public final static < T > Optional < Seq < T > > streamToOptional ( final Stream < T > stream ) { final List < T > collected = stream . collect ( java . util . stream . Collectors . toList ( ) ) ; if ( collected . size ( ) == 0 ) return Optional . empty ( ) ; return Optional . of ( Seq . fromIterable ( collected ) ) ; }
Create an Optional containing a List materialized from a Stream