How to use / refer to the negation of a boolean function in Scala?

前端 未结 4 1360
梦如初夏
梦如初夏 2020-12-23 21:51

I\'m trying to use the negation of a boolean function in Scala, such as:

def someFunction(x: Set, p: Int => Boolean): Boolean = 
    someOtherFunction(x,          


        
4条回答
  •  心在旅途
    2020-12-23 22:05

    The negation of p is a function that applies p to its argument and negates the result.

    x => !p(x)
    

    If you want to be able to write !p or p && q you can use this library, which pimps functions that return a bool with various logical operators.

提交回复
热议问题