0

I have a method that I call using Parallel Streams. the call is as follows :

myList.parallelStream().forEach(f -> doWork(f));

This works as is but I now have a need for doWork to return a boolean signifying whether it failed or succeeded in "Doing Work". Is there a simple way to do something like this ?

myList.parallelStream().forEach(f -> 
    if ( doWork(f) ) {
        incrementSuccessCounter;
    } else {
        incrementFailedCounter;
    } 
)

The above does not work but i'm wondering if there is an accepted/standard solution to this situation.

Deslyxia
  • 619
  • 4
  • 11
  • 32
  • Why does the above not work? Did you miss the block around the `if / else`? Alternatively, you can use a ternary operator: that doesn't require a block. – Tunaki May 06 '16 at 17:42
  • It doesnt like if / else logic being a part of the parallel stream call. And doesnt see f as in scope . – Deslyxia May 06 '16 at 17:46

0 Answers0