Skip to content

Instantly share code, notes, and snippets.

@wheaties
Created June 12, 2013 02:37
Show Gist options
  • Save wheaties/5762459 to your computer and use it in GitHub Desktop.
Save wheaties/5762459 to your computer and use it in GitHub Desktop.
A shapeless Predicate?
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