title: Limit a stream by a predicate
body: <p>Is there a Java 8 stream operation that limits a (potentially infinite) <code>Stream</code> until the first element fails to match a predicate?</p>
  
  <p>In Java 9 we can use <code>takeWhile</code> as in the example below to print all the numbers less than 10.</p>
  
  <pre><code>IntStream
      .iterate(1, n -&gt; n + 1)
      .takeWhile(n -&gt; n &lt; 10)
      .forEach(System.out::println);
  </code></pre>
  
  <p>As there is no such operation in Java 8, what's the best way of implementing it in a general way? </p>