简体   繁体   中英

Concatenating HList Types in Case Class Definition

I have three HLists A , B and R . Within a case class definition I want to enforce a relationship between those three HLists.

The code looks like this:

trait Base[A <: HList]    
case class Concat[A <: HList, B <: HList, R <: HList](a: A, b: B) extends Base[R]

Is it possible to enforce that R is a concatenation of the HLists A and B ? Or is there a way that I do not need the type R but still enforce that the type parameter of Base is a concatenation of A and B ?

You want Prepend :

case class Concat[A <: HList, B <: HList, R <: HList](a: A, b: B)(implicit p: Prepend.Aux[A, B, R]) extends Base[R]

And a useful companion method for constructing without specifying R

def concat[A <: HList, B <: HList](a: A, b: B)(implicit p: Prepend[A, B]): Concat[A, B, p.Out] = Concat(a, b)(p)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM