title: Getting prime factors in functional Java streams with a single method?
body: <p>This method will take in a <code>Long</code> and return a <code>LongStream</code> of prime numbers for any digit passed to the method.</p>
  
  <p><strong>factors.java</strong></p>
  
  <pre><code>public LongStream factors(long x){
    LongStream factorStream = LongStream.range(1, x+1).filter(n -&gt; x%n == 0);
    return factorStream;
  }
  </code></pre>
  
  <p>Utilizing the above method to find common factors first is <strong>ok</strong>.</p>
  
  <p><strong>primeFactors.java</strong></p>
  
  <pre><code>public LongStream primeFactors(long x){
    LongStream primeFactorStream = factors(x).filter(n -&gt; factors(n).count() == 0); 
    //doesn't work as factors.java returns a LongStream, which might include non-prime factors, which will not equate to zero.
    return primeFactorStream;
  }
  </code></pre>
  
  <p>I understand this should be easily circumvented with the use of a simple <strong>isPrime()</strong> method with a predicate, but is there a way to do the same thing for for <em>prime factors</em> but only with a single method? </p>