While reviewing another Scala implementation of the Game of Life, I ended up drastically rewriting it.  The board is represented as a Set[(Int, Int)] containing the coordinates of the live cells.I'm not sure whether the case class is appropriate here, and not too happy about the long parameter list.  I'm also dissatisfied with the implementation of parse.import java.io.Fileimport java.nio.file.Filescase class GameOfLife(living: Char='X', dead: Char=' ', height: Int=0, width: Int=0, liveCells: Set[(Int, Int)]=Set()) {  /**   * Parses a string representation of the board.  Returns a GameOfLife   * object whose dimensions are at least as large as the current board,   * and expanded if necessary.   */  def parse(board: String): GameOfLife = {    var h = height    var w = width    val cells = board.lines.zipWithIndex.flatMap({case (line, r) => {      h = h max (r + 1)      line.view.zipWithIndex.flatMap({        w = w max line.length        _ match {          case (`living`, c) => Some((r, c))          case _             => None        }      })    }}).toSet    GameOfLife(living, dead, h, w, cells)  }  override def toString = {    (0 to height).map((r) =>      (0 to width).map((c) => if (isLive((r, c))) living else dead).mkString    ).mkString(\n)  }  private val neighborOffsets = Set(    (-1, -1), (-1,  0), (-1, +1),    ( 0, -1),           ( 0, +1),    (+1, -1), (+1,  0), (+1, +1)  )  private def neighbors(cell: (Int, Int)): Set[(Int, Int)] = {    neighborOffsets.map(offset => (cell._1 + offset._1, cell._2 + offset._2))                   .filter(isInBounds)  }  def isLive(cell: (Int, Int)): Boolean = liveCells.contains(cell)  def isInBounds(cell: (Int, Int)): Boolean = {      0 <= cell._1 && cell._1 < height &&      0 <= cell._2 && cell._2 < width  }  def nextGen(): GameOfLife = {    val candidates = liveCells.flatMap(neighbors).union(liveCells)    GameOfLife(living, dead, height, width, candidates.filter(c => {      neighbors(c).count(isLive) match {        case 2 => isLive(c)        case 3 => true        case _ => false      }    }))  }}object GameOfLife {  def main(args: Array[String]): Unit = {    val initBoard = new String(Files.readAllBytes(new File(args(0)).toPath))    val initGame = GameOfLife().parse(initBoard)    lazy val generations: Stream[GameOfLife] = initGame #:: generations.map(_.nextGen)    generations.takeWhile(!_.liveCells.isEmpty).foreach(println)  }}
Game of Life in Scala with a sparse representation
scala;game of life