Skip to content

@densh /Functionable.scala
Last active

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
import scala.reflect.macros.{Context => Ctx}
import scala.language.experimental.macros
trait Functionable[T]
object Functionable {
implicit def materialize[T]: Functionable[T] = macro materialize_impl[T]
def materialize_impl[T](c: Ctx)(implicit ttag: c.WeakTypeTag[T]): c.Expr[Functionable[T]] = {
val funcs = (0 to 22).map { c.universe.definitions.FunctionClass(_) }.toList
if (funcs.exists { ttag.tpe.typeSymbol == _ })
c.universe.reify { new Functionable[T] { } }
c.abort(c.macroApplication.pos, "not a function")
object Macro {
def apply[T](f: T)(implicit functionable: Functionable[T]) = macro impl[T]
def impl[T](c: Ctx)(f: c.Expr[T])(functionable: c.Expr[Functionable[T]])(implicit ttag: c.WeakTypeTag[T]): c.Expr[String] = c.literal(ttag.tpe.toString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.