0

I have a String representation as below that I would like to represent as a HList. Here is it:

123456,/02/2017,0,0,0,0,0,0,170.153

So the type that I'm interested in is:

Int :: DateTime :: Seq[Double]

I was able to manage one-to-one mapping done, but how could I convert my representation above to the Shapeless type that I would want to? Any suggestions?

joesan
  • 13,963
  • 27
  • 95
  • 232

1 Answers1

2

I'm not sure where's your trouble. Why can't you just do something like:

def hlistFromString(s: String): Int :: Date :: Seq[Double] :: HNil = {
  val ss = s.split(',')
  ss(0).toInt :: new Date(ss(1)) :: ss.toSeq.drop(2).map(_.toDouble) :: HNil
}

val s = "123456,01/02/2017,0,0,0,0,0,0,170.153"
println(hlistFromString(s))

Output is

123456 :: Mon Jan 02 00:00:00 2017 :: ArrayBuffer(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 170.153) :: HNil

The only guess I have is that you missed that any HList type should end with HNil

SergGr
  • 23,570
  • 2
  • 30
  • 51