Skip to content

Instantly share code, notes, and snippets.

@xeno-by xeno-by/gist:9619590
Created Mar 18, 2014

Embed
What would you like to do?
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
You can’t perform that action at this time.