Leaning functional program in Scala