I face the same problem often. I need to count the runs of a lambda for use outside the lambda.
E.g.:
myStream.stream().filter(...).forEa
AtomicInteger runCount = new AtomicInteger(0); elements.stream() //... .peek(runCount.incrementAndGet()) .collect(Collectors.toList()); // runCount.get() should have the num of times lambda code was executed