×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Scala
Posted by: osocron coder
Added: Sep 22, 2016 10:05 PM
Views: 5
How to create infinite prime numbers!
  1. def from(n: Int): Stream[Int] = n #:: from(n + 1)
  2. def primes = from(1).filter(n => (2 until n).forall(x => n % x != 0) )
  3. primes.take(50).foreach(println)