Created
January 15, 2013 12:39
-
-
Save rafaeldff/4538359 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// now: | |
def query[T](predicate: T => Boolean): List[T] = macro queryMacro | |
def queryImpl[T: c.TypeTag](c: Context)(predicate: c.Expr[T => Boolean]): c.Expr[List[T]] | |
// with something like closure reflection: | |
// the library: | |
class ReflectiveClosure[A,B] extends Function1[A,B] { | |
def ast: Expression | |
} | |
implicit def reflectClosure[A,B](f: Function1[A,B]): ReflectiveClosure[A,B] = macro reflectiveClosureImpl | |
def reflectiveClosureImpl[A: c.TypeTag, B: c.TypeTag](c:Context)(f:c.Expr[Function1[A,B]]):c.Expr[ReflectiveClosure[A,B]] = ??? | |
// the consumer: | |
def query[T](predicate: ReflectiveClosure[T,Boolean]): List[T] = { | |
val ast = predicate.ast | |
??? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment