@ SafeVarargs private static < T extends Snippet > Stream < T > nonEmptyStream ( Supplier < Stream < T > > supplier , SnippetPredicate < T > ... filters ) { for ( SnippetPredicate < T > filt : filters ) { Iterator < T > iterator = supplier . get ( ) . filter ( filt ) . iterator ( ) ; if ( iterator . hasNext ( ) ) { return StreamSupport . stream ( Spliterators . spliteratorUnknownSize ( iterator , 0 ) , false ) ; } } return null ; }
Apply filters to a stream until one that is non - empty is found . Adapted from Stuart Marks