Scala book exsercise