Scala Macros: Making a Map out of fields of a class in Scala

Note that this can be done much more elegantly without the toString / c.parse business: import scala.language.experimental.macros abstract class Model { def toMap[T]: Map[String, Any] = macro Macros.toMap_impl[T] } object Macros { import scala.reflect.macros.Context def toMap_impl[T: c.WeakTypeTag](c: Context) = { import c.universe._ val mapApply = Select(reify(Map).tree, newTermName(“apply”)) val pairs = weakTypeOf[T].declarations.collect { case m: MethodSymbol … Read more

Weird behavior trying to convert case classes to heterogeneous lists recursively with Shapeless

This now works more or less as written using recent shapeless-2.1.0-SNAPSHOT builds, and a close relative of the sample in this question has been added there as an example. The problem with the original is that each expansion of a Generic introduces a new HList type into the implicit resolution of the DeepHLister type class … Read more