Created
March 18, 2014 13:01
-
-
Save xeno-by/9619590 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
import scala.language.experimental.macros | |
import scala.reflect.macros.Context | |
import scala.annotation.StaticAnnotation | |
class csvTyped(val sample: String)(funcs: (String => Any)*) extends StaticAnnotation { | |
def macroTransform(annottees: Any*): Any = macro Macros.impl | |
} | |
object Macros { | |
def impl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = { | |
import c.universe._ | |
val Apply(Select(Apply(Apply(_, List(Literal(Constant(macroArgument: String)))), functions), _), _) = c.macroApplication | |
val types = functions.map(func => c.typeCheck(func, typeOf[String => Any], silent = false, withImplicitViewsDisabled = false, withMacrosDisabled = false).tpe).map { | |
case TypeRef(_, fn1, _ :: returnType :: Nil) if fn1 == typeOf[Function1[_, _]].typeSymbol => returnType | |
} | |
??? | |
} | |
} | |
======= | |
@csvTyped("sample.csv")(_.toDouble) | |
object Test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment