Functional programming in Scala