将高阶函数转换为匿名函数的Scala语法是否正确?

将高阶函数转换为匿名函数的Scala语法是否正确?,scala,functional-programming,anonymous-function,higher-order-functions,Scala,Functional Programming,Anonymous Function,Higher Order Functions,我想在下面的示例中消除逆函数,只需在调用bar时直接创建一个匿名函数。有人能建议正确的语法吗?我尝试了一些变体,但无法编译任何内容 object Test { def foo(p: Int => Boolean): Boolean = { def inverse(p: Int => Boolean): Int => Boolean = { e: Int => !p(e) } bar(inverse(p)) } def

我想在下面的示例中消除
函数,只需在调用
bar
时直接创建一个匿名函数。有人能建议正确的语法吗?我尝试了一些变体,但无法编译任何内容

object Test {

  def foo(p: Int => Boolean): Boolean = {
    def inverse(p: Int => Boolean): Int => Boolean = {
      e: Int => !p(e)
    }

    bar(inverse(p))
  }

  def bar(p: Int => Boolean): Boolean = true

}
这应该行得通

bar(!p(_))

stackoverflow说这个答案太短了。

我不知道scala,但是
bar((e:Int)=>!p(e))
呢?编辑:呃,代码读得不够好