From n00b scala code to functional code