I would like to get value of a nested case class giving a "path" in this nested case class.
For example, giving:
case class Address(street : String, city : String, postcode : String)
// Nested case class
case class Person(name : String, age : Int, address : Address)
val person = Person("Joe Grey", 37, Address("Southover Street", "Brighton", "BN2 9UA"))
val path = "address_street" // _ is arbitrary separator
I would like getter(path)
returns "Southover Street".
I try different things with shapeless' lenses like
val steetLens = lens[Person] >> Witness(Symbol("address")) >> Witness(Symbol("street"))
println(steetLens.get(person))
which return the right thing but I can't use it in a generic way because something like this:
val steetLens = lens[Person] >> addressField >> streetField
doesn't work..
As far as I understand we can't create Symbol
from generic string.