Is there a Java 8 stream operation that limits a (potentially infinite) Stream until the first element fails to match a predicate?
Stream
In Java 9 we can use
Here is my attempt using just Java Stream library.
IntStream.iterate(0, i -> i + 1) .filter(n -> { if (n < 10) { System.out.println(n); return false; } else { return true; } }) .findAny();