How can I modify my Akka streams Prime sieve to exclude modulo checks for known primes?
问题 I wrote a sieve using akka streams to find prime members of an arbitrary source of Int : object Sieve extends App { implicit val system = ActorSystem() implicit val mat = ActorMaterializer(ActorMaterializerSettings(system)) implicit val ctx = implicitly[ExecutionContext](system.dispatcher) val NaturalNumbers = Source.fromIterator(() => Iterator.from(2)) val IsPrimeByEurithmethes: Flow[Int, Int, _] = Flow[Int].filter { case n: Int => (2 to Math.floor(Math.sqrt(n)).toInt).par.forall(n % _ != 0)