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