Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass in Streams Prev element result to next one

I have List of items where on each item I need to create some calculation. Each calculation is built by the preceding element.

So for example:

List<Object> Users=new ArrayList<>();
users.stream().filter(element->calculateSomething(<need-prev-element-input>).findFirst();

The calculateSomething will return true/false depends on the prev element calculation result in the stream

Any idea how can I do that?

like image 310
rayman Avatar asked Dec 19 '22 06:12

rayman


1 Answers

Streams are not designed to be able to do any operation like this. You might be able to hack something together to do that, but it'll be awful; you should go back to using normal loops instead.

like image 85
Louis Wasserman Avatar answered Jan 12 '23 19:01

Louis Wasserman