Created
June 12, 2013 02:37
-
-
Save wheaties/5762459 to your computer and use it in GitHub Desktop.
A shapeless Predicate?
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
import shapeless._ | |
import Poly._ | |
import TypeOperators._ | |
trait PredF extends (Id ~>> Boolean){ | |
self => | |
def apply[T](arg: T): Boolean | |
def or(that: Id ~>> Boolean) = new PredF{ | |
def apply[T](arg: T) = self(arg) || that(arg) | |
} | |
def and(that: Id ~>> Boolean) = new PredF{ | |
def apply[T](arg: T) = self(arg) && that(arg) | |
} | |
def xor(that: Id ~>> Boolean) = new PredF{ | |
def apply[T](arg: T) = if(self(arg)) !that(arg) else that(arg) | |
} | |
} | |
//Dunno if this'll work... | |
object NotF{ | |
def apply(that: Id ~>> Boolean) = !that(_) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment