可能重复的否定:
How to use/refer to the negation of a boolean function in Scala?斯卡拉 - 谓语
我目前正在马丁·奥德斯基的斯卡拉课程coursera。在其中一项任务中,我需要对一个函数的否定(代表一个谓词)进行研究。
def fun1 (p: Int => Boolean): Boolean = {
/* some code here */
}
假设文字p: Int => Boolean
功能代表了某种谓词像x => x > 0
def fun2 (p: Int => Boolean): Boolean = {
val x = fun1 (p)
val y = ???
/* How can I call the negation of the predicate 'p' here? */
return x && y
}
例如,如果我称之为fun2
为fun2 (x => x > 0)
我给了很多心思,但我没有取得任何进展。我没有要求解决任何分配问题(我坚持荣誉代码,我相信),但任何我在这里失踪的解释都会有很大的帮助。
看看这篇文章:http://stackoverflow.com/questions/12681616/how-to-use-refer-to-the-negation-of-a-boolean-function-in-scala –