Skip to content

Instantly share code, notes, and snippets.

@rafaeldff
Created January 15, 2013 12:39
Show Gist options
  • Save rafaeldff/4538359 to your computer and use it in GitHub Desktop.
Save rafaeldff/4538359 to your computer and use it in GitHub Desktop.
// 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