Как можно упростить следующую реализацию «решета Эратосфена»?
package tail
import scala.annotation.tailrec
class EratosphenSieve(upperBound : Int) {
    def sieve() : Array[Int] = {
        val inputData = (2 to upperBound).toArray
        sieveRun(inputData, 0, inputData)
    }
    @tailrec
    private def sieveRun(inputData : Array[Int], index : Int, resData : Array[Int]) : Array[Int] = {
        if(index > 0 && inputData.length == resData.length)
        {
            resData
        }else {
            val primary = resData.apply(index);
            sieveRun(resData, index + 1, resData.filter(func => func == primary || func % primary != 0));
        }
    }
}
Всем приятного отдыха )
Перемещено post-factum из talks













