case class with dynamic Param

25 views
Skip to first unread message

Tong Li Ken

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

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?

eg.

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

unread,
Jun 13, 2016, 12:16:13 AM6/13/16
to treehugg...@googlegroups.com
Hi,

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

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


-eugene


--
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 treehugger-sca...@googlegroups.com.
To post to this group, send email to treehugg...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/treehugger-scala/31a63dec-992b-4a33-8d60-fbef131802f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Tong Li Ken

unread,
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
Forward
0 new messages