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
}
This should work
bar(!p(_))
stackoverflow says this answer is too short.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.