FP in Scala exercise