3

I would like to eliminate the inverse function in the example below and just create an anonymous function directly in the call to bar. Can anyone suggest the correct syntax? I've tried a few variations but can't get anything to compile.

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

}
1
  • 3
    I don't know scala, but what about bar((e:Int) => !p(e))? Edit: err, didn't read the code good enough Commented Oct 4, 2012 at 7:50

1 Answer 1

13

This should work

bar(!p(_))

stackoverflow says this answer is too short.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.