Skip to content

Instantly share code, notes, and snippets.

Created January 23, 2014 15:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import scala.reflect.runtime.universe._
def classType[T](c: Class[T]): Type =
def prodType(p: Product): Type = {
val mirror = runtimeMirror(p.getClass.getClassLoader)
val cSym = mirror.staticClass(p.getClass.getName)
def tagType[T <: Product : TypeTag] = typeOf[T]
case class CC1(name: String, stuff: Traversable[Any])
object O1 {
case class CC2(i: Int, x: Double)
val cc1 = CC1("foo", Map("one" -> 3, "two" -> 3, "three" -> 5, "four" -> 4))
val cc2 = O1.CC2(22, 2.2)
// Exiting paste mode, now interpreting.
scala> tagType[CC1]
res1: reflect.runtime.universe.Type = CC1
scala> prodType(cc1)
res2: reflect.runtime.universe.Type = $line3.iw$CC1
scala> tagType[O1.CC2]
res3: reflect.runtime.universe.Type = O1.CC2
scala> prodType(cc2)
res4: reflect.runtime.universe.Type = $line3.iw$O1$CC2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment