Understanding Scala high order function