Skip to content

Instantly share code, notes, and snippets.

@MasseGuillaume
Created February 24, 2014 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MasseGuillaume/9194161 to your computer and use it in GitHub Desktop.
Save MasseGuillaume/9194161 to your computer and use it in GitHub Desktop.
Worksheet using scala reflexion toolbox
val code = """def html[X, Y](xs: List[(X, Y)]) = xs.toString
val a = List((1,1))
a
val b = List((1,1))
b"""
val tree = tb.parse(code)
val identifiers = tree.children.collect{ case i @ Ident(_) => i }
val instrumentation = identifiers.map{ i =>
Apply(Select(Ident("scala"), TermName("Tuple2")),
List(Literal(Constant(i.pos.line)),
Apply(Ident(TermName("html")), List(i))
)
)
}
val result = Apply(Ident(TermName("List")), instrumentation)
tb.eval(Block(tree.children, result)).asInstanceOf[List[(Int, Any)]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment