implement Exercise 2 from "FP in Scala" book