I was wondering whether Scala supports recursive macro expansion e.g. I am trying to write a lens library with a lensing macro that does this:
case class C(d: Int)
case class B(c: C)
case class A(b: B)
val a = A(B(C(10))
val aa = lens(a)(_.b.c.d)(_ + 12)
assert(aa.b.c.d == 22)
Given lens(a)(_.b.c.d)(f)
, I want to transforms it to a.copy(b = lens(a.b)(_.c.d)(f))
EDIT: I made some decent progress here
However, I cannot figure out a generic way to create an accessor out of List[TermName]
e.g. for the above example, given that I have List(TermName('b'), TermName('c'), TermName('d')))
, I want to generate an anonymous function _.b.c.d
i.e. (x: A) => x.b.c.d
. How do I do that?
Basically, how can I write these lines in a generic fashion?