Functional Programming Principles in Scala, assignment 3