So the problem is in title. Here r some exaplanations:
As we know, we can use HList
to store objects with its types.
SomeCL[Int], SomeCL[String], SomeCL[MyType1] :: ... :: HNil
Where SomeCL
is some class. So I want to make make map, which can store information about all types inside, smth like:
// it is wrong usage of HMap, it is an example of how I want it be
HMap("string1" -> SomeCL[Int], "string2" -> SomeCL[MyType1], ... )
And not to loose information about types. I want to notice, that object types and number of objects r unknown, so we cant use lots of implicits for native shapeless HMap
. Is it possible?
EDITED
(I meant that we have no possibility to write manually all implicit type convertions for shapeless HMap
)
P.S.
If it is not possible, how can i decide such problem: For example I have some objects in HList
, and I am building graph. It is very important to safe type of each node (we create nodes from objects in HList
), and I dont know the number of objects. How can i build graph, and not to loose information about types?
EDITED2
Btw, this code will throw an error, if S
is the super type of A
and C
; how can we avoid this?
class SomeCL[T](val l: T) {
}
class NodeMap[K, V]
implicit val si = new NodeMap[String, SomeCL[A]]
implicit val sd = new NodeMap[String, SomeCL[S]]
implicit val sb = new NodeMap[String, SomeCL[C]]
val hm = HMap[NodeMap]("foo" -> new SomeCL(new A), "bar" -> new SomeCL(new S), "lol" -> new SomeCL(new C))