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