Conway life game implementation with scala
The main-things I changed:


Matrix is now completely immutable
Code is more self-documenting (extract complex code to methods, etc.)
I deleted the unnecessary inheritance
I don't like apply-methods which are used as contains-methods -> name change
I deleted parentheses in side-effect free methods
Many syntax improvements


The code:

object LifeGame extends App {
  case class Point(x: Int = 0, y: Int = 0)

  object Matrix {
    def empty: Matrix =
      Matrix(Set.empty)
  }

  case class Matrix(private val data: Set[Point]) {

    def contains(p: Point): Boolean =
      data contains p

    def update(p: Point, b: Boolean) =
      if (b) copy(data+p) else copy(data-p)

    def iterator: Iterator[Point] =
      data.iterator

    override def toString = {
      def best(func: (Int, Int) =&gt; Int)(p1: Point, p2: Point) =
        Point(func(p1.x, p2.x), func(p1.y, p2.y))

      val minBoundary = (Point() /: iterator) { best(math.min) }
      val maxBoundary = (Point() /: iterator) { best(math.max) }

      val sb = StringBuilder.newBuilder
      for (i &lt;- minBoundary.x to maxBoundary.x) {
        sb.append("\n")
        for (j &lt;- minBoundary.y to maxBoundary.y) {
          sb.append(if (this contains Point(i, j)) "x" else " ")
        }
      }
      sb.append("\nmin=%s, max=%s" format (minBoundary, maxBoundary))
      sb.toString
    }
  }

  object Engine {

    def newCell: (Boolean, Int) =&gt; Boolean = {
      case (true, 0 | 1) =&gt; false
      case (true, 2 | 3) =&gt; true
      case (true, _) =&gt; false
      case (false, n) =&gt; n == 3
    }

    def apply(input: Matrix): Matrix = {
      def block1D(i: Int) =
        Seq(i-1, i, i+1)

      def block2D(p: Point) =
        for (x &lt;- block1D(p.x); y &lt;- block1D(p.y)) yield Point(x, y)

      def points =
        (input.iterator flatMap block2D).toSet.par

      def calcCell(p: Point) = {
        val neighbours = block2D(p) filter { p != }
        val alive = neighbours map { input contains } count { true == }

        if (newCell(input contains p, alive)) Some(p)
        else None
      }

      val cells = (points map calcCell).seq collect { case Some(p) =&gt; p }
      (Matrix.empty /: cells) { (result, p) =&gt; result(p) = true }
    }
  }
}