Scala implementation of "Functional Pearls"