Scenario: I have an object with two functions →
<Integer> getA(); <Integer> getB();
I have a list of objects, for example List<MyObject> myObject.
Purpose Iterate over the list and get the sum of A and B in the list of objects.
My decision
myObject.stream().map(a -> a.getA()).collect(Collectors.summingDouble());
myObject.stream().map(a -> a.getB()).collect(Collectors.summingDouble());
Question: How can I do this at the same time? This way, I don't have to iterate over the original list twice.
@Edit: I did this because some of the filters that I used were O (n ^ 3). The view is really bad to do it twice.
Benchmark: it is really important if it is T or 2T, when the program runs for half an hour on i5. This was on much smaller data, and if I started the cluster, my data would also be large.
It doesn't matter if you can do it on one line!