Reputation: 431
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
}
Upvotes: 3
Views: 952
Reputation: 81988
This should work
bar(!p(_))
stackoverflow says this answer is too short.
Upvotes: 13