exercise of "Functional Programming Principles in Scala"