case class with dynamic Param

Skip to first unread message

Tong Li Ken

Jun 13, 2016, 12:05:27 AM6/13/16
to treehugger-scala

I need to generate a case class and the param will be dynamic based on a map.
val param = Map("id" -> "String", "time" -> "String", "value" -> "Double")
How can i do this?


case class dp (id : String, time: String, value : Double)
case class dpAll (id: String, time: String, temp: Double, hum: Double, light: Double)

The parameters name and type are not fixed as well as the number of parameter.

eugene yokota

Jun 13, 2016, 12:16:13 AM6/13/16

Here's how you define a case class -
The built-in classes under `definitions` (e.g. String is called StringClass) that are typically imported as:

    import treehugger.forest._, definitions._, treehuggerDSL._


You received this message because you are subscribed to the Google Groups "treehugger-scala" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
To view this discussion on the web visit
For more options, visit

Message has been deleted

Tong Li Ken

Jun 13, 2016, 3:05:58 AM6/13/16
to treehugger-scala
Hi Eugene, 

Thanks for the quick response, I think i did not state my question correctly.
Let's assume that i have a list of param of string: a, b ,c 

val aList = List("a", "b", "c")

I will need something like this:

def foo(valStrings: List[String]) : Tree = {
      CASECLASSDEF("foo") withParams(
          valStrings map { x => PARAM(x, StringClass) }

The case class will have dynamic number of  parameter and type (not necessary String).
The above will have error: overloaded method value withParams......
Reply all
Reply to author
0 new messages