Scala (Slick) HList splitting to case classes

520 Views Asked by At

currently I have a HList with more than 22 fields and now I want to split it to

2-3 case classes, is there an easy functional way to do it? Currently I use the following syntax:

CaseClass1(c.head, c.tail.head, c.tail.tail.head, etc...)

However that doesn't seem to be right since I have a really big tail part now..

1

There are 1 best solutions below

4
On BEST ANSWER

Using the tuple functionality in shapeless you could do:

import shapeless._
import syntax.std.tuple._

case class Foo(a: Int, b: String)

val hlist =  1 :: "a" :: 2 :: "b" :: HNil
Foo.tupled(hlist.take(2).tupled)