def isZero(x: Int) = x == 0
def eval(x: Int, g: Int => Boolean) = g(x)
//Just passes 0 and f to eval
def passToEval(f: Int => Boolean): Boolean = {
eval(0, f)
}
//true
passToEval(isZero)
问题是,如何将f传递给方法,eval? 我对涉及passToEval
参数的变通方法不感兴趣答案 0 :(得分:4)
您可以定义一个函数来否定其输入函数并传递:
def not[A](f: A => Boolean) = (x: A) => !f(x)
passToEval(not(isZero))