Return first result matching predicate in a Java stream or all non-matching results

I have a Validator interface which provides a isValid(Thing) method, returning a ValidationResult which contains a boolean and a reason message.

I want to create a ValidatorAggregator implementation of this interface which performs an OR across multiple Validators (if any Validator returns a positive result, then the result is positive). If any validator succeeds, I'd like to short-circuit and just return its result. If no validator succeeds, I want to return all of the failure messages.

I can do this succinctly using a stream and findFirst().orElse(...) but using this pattern I lose all the intermediate results if findFirst returns empty:

public ValidationResult isValid(final Thing thing) {
      .map(v -> validator.isValid(thing))
      .orElseGet(() -> new ValidationResult(false, "All validators failed'));

Is there any way to capture the failed results using a stream, or indeed just more succinctly than the below?

public ValidationResult isValid(final Thing thing) {
    final Set<ValidationResult> failedResults = new HashSet<>();
    for (Validator validator : validators) {
        final ValidationResult result = validator.isValid(thing);
        if (result.isValid()) {
            return result;
    return new ValidationResult(false, "No successful validator: " + failedResults); 
    // (assume failedResults stringifies nicely)

Edit: based on comments, I agree what I'm trying to do is premature optimisation (particularly as these validators are very lightweight). I'll probably go with something similar to Holger's solution of computing all validations and partitioning into successful/unsuccessful results.

This was marked as a dupe of Can you split a stream into two streams? and the partitioningBy answer sort-of is, but I think this question is asking, and the discussion answering, a different problem.


I'm stuck. Coming from C++ I thought this would simply work, but it does not. Can you please give me an advice? I will try to not end up with kind of creation method in each class used for T. public ...

Is there a way to set a button key event in Java so that Alt does not have to be pressed. For example, when this is used setMnemonic(KeyEvent.VK_DELETE) it is required for Alt + Delete to be pressed ...

Below is a code snippet of ArrayList, which either takes in the 'initialCapacity' provided by the user or default of 10. My question - why was 10 not a static constant ? I guess constants are used ...

If I have a regular expression, how do I return the substring that it has found? I'm sure I must be missing something obvious, but I've found various methods to confirm that that substring is ...