Understanding scala high order function