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 = 0L; long runCount = myStream.stream() .filter(...) .peek(item -> { foo(); bar(); runCount.incrementAndGet(); }); System.out.println("The lambda ran " + runCount.incrementAndGet() + "times");