I have a problem that, in my opinion, would be ideal for threads and / or lambda. On the other hand, I do not want to re-complement this, but since he will use this particular technique in many ways (the launch function in the sublist), I would like some ideas on how to get this right from the very beginning.
I have a List<Product> productList .
I want to be able to productList over all signatures in a productList . For example, all sublists with size = 30. This sublist should then be used as an argument to the function.
This is my current, naive solution:
List<Product> products=... // This example uses sublists of size 30 for (int i = 0; i < products.size() - 29; i++) { // sublist start index is inclusive, but end index is exclusive List<Product> sublist = products.subList(i, i + 30); Double res = calc(sublist); } // an example of a function would be moving average
How will this be implemented using lambdas?
EDIT I ββtried to come up with the simplest possible example to illustrate the problem. After some comments, I realized that the ideal example is moving average calculation. The first MAVG is calculated on the sublist [0..29], the second on [1..30], the third on [2.31], etc.
source share