implement exercises 1-3 from "FP in Scala" book, chapter 3