I want to create a group of elements in a message as in below image
Updated:
case class Element(key:String;value:String)
If I understand the domain correctly, something like this should work:
case class Message(entries: List[Entry])
case class Entry(name: String, value: Value)
trait Value
object Value {
case class Single (v: String) extends Value
case class Group (entries: List[List[Entry]]) extends Value
}
Message(
Entry("Key 1", Value.Single("Value 1")),
Entry("Key 2", Value.Group(
List(
List(
Entry("Key 3", Value.Single("Value 3")),
Entry("Key 4", Value.Single("Value 4"))
),
List(
Entry("Key 3", Value.Single("Value 5")),
Entry("Key 4", Value.Single("Value 6"))
)
)
))
)
Of course some helper functions could be created to make a nicer DSL for it.