Prime number verifier
How about this?

def isPrime(n:Int):Boolean = n match {
  case 1 =&gt; false
  case 2 =&gt; true
  case 3 =&gt; true
  case 5 =&gt; true
  case 7 =&gt; true
  case n if (n%2==0 || n%3==0 || n%5==0 || n%7==0) =&gt; false
  case _ =&gt; (Stream.iterate(3, Math.sqrt(n).toInt+1){_ + 2} dropWhile((x:Int) =&gt; n%x != 0)).isEmpty
}


The code is straightforward. We know that the prime numbers below 10 are 2, 3, 5, 7. If a given number is the multiple of 2, 3, 5, or 7, is't not a prime. In other case (the last case branch) it generates stream from 3 to ceil(sqrt(n)) with step 2. We know that even numbers can't be a prime. And check that the argument is a multiple of any number in the stream. Basically the same logic with the original code. The reason I use Stream is to use lazy evaluation. With lazy evaluation, we can avoid unnecessary computation.