// the results can be anything, errors always start with 'ERROR'
List<String> results= {
"Success 100 - Operation worked John",
"Success 100 - It also worked for Harry",
"ERROR 4514 for Sally. It's always Sally."
}
// I want this to output something like
// warn: There were errors
// warn: ERROR 4514 for Sally. It's always Sally.
//
// in the case there are no ERROR's I want no warn:'s
results.stream()
.filter( name->name.startsWith( "ERROR" ) )
.DO_THIS_IF_NOT_EMPTY( ()-> LOG.warn( "There were errors"; )
.forEach( error -> { LOG.warn( "ERROR: " + error }
The DO_THIS_IF_NOT_EMPTY is wishful. I don't see an obvious elegant way to do this with java streams. Can anyone think of a good one?