3

我想消除inverse下面示例中的函数,直接在调用中创建一个匿名函数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

}
4

1 回答 1

13

这应该工作

bar(!p(_))

stackoverflow 说这个答案太短了。

于 2012-10-04T07:49:05.380 回答