Functional programming principles in scala