Created
October 16, 2011 15:26
-
-
Save kaja47/1291030 to your computer and use it in GitHub Desktop.
Boolean function composition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait F[T] extends Function1[T, Boolean] { | |
def apply(t: T): Boolean | |
def &&(g: T => Boolean) = (a: T) => apply(a) && g(a) | |
def ||(g: T => Boolean) = (a: T) => apply(a) || g(a) | |
def ^ (g: T => Boolean) = (a: T) => apply(a) ^ g(a) | |
def unary_! = (a: T) => !apply(a) | |
} | |
implicit def toF[T](a: T => Boolean) = new F[T] { def apply(x: T) = a(x) } | |
// *** | |
val f: Int => Boolean | |
val g: Int => Boolean | |
val h: Int => Boolean | |
val c: Int => Boolean = !f && g || h |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment