Functional Programming Principles in Scala, assignment 2