Assuming I have a value case class
case class Id(i:Int) extends AnyVal
and a sequence containing this value case class
Seq(Id(1), Id(2), Id(3))
is there a way of converting those values into Int
without that there is a need of iteration over the sequence (e.g. by doing Seq(Id(1), Id(2), Id(3)).map(_.i)
?
The reason I ask is that I think that the nice thing about value case classes is that you can use value classes that have native types as representation during runtime and are thus extremely efficient. But not all libraries in use do support an automatic "conversions" of those classes. Thus one has to pass the native type what is no big deal when it is a simple attribute since the compiler can optimize it. But when having a sequence I have to explicitly map it, which means that there happens an unnecessary iteration over all values, because it is actually doing nothing but mapping to the same values at runtime. Is there any way to avoid that and use some optimizations of the compiler in such cases?