How to create a constrained HList from a sequence?

Viewed 203

I have a constructor that has the following signature:

class Event[DL <: HList](
  detailsIn: DL
)(implicit lbcr: LUBConstraint[DL, EventDetail[_]]) { ... 

In the companion object I have:

  def apply[DL <: HList](
    detailIn: String*
  )(implicit lbcr: LUBConstraint[DL, EventDetail[String]]) =
    new Event(
      if (detailIn.map(deet => EventDetail(deet)).toList.size == 1)
        detailIn.map(deet => EventDetail(deet)).toList.toHList[String :: HNil].get
      else throw new NotImplementedException()
    )(lbcr)

Admittedly, this apply method could be cleaned up.

This yields the following error which I'm frankly lost about how to deal with:

Error:(87, 7) type mismatch;
 found   : shapeless.LUBConstraint[DL,edu.cornell.ansci.dairy.econ.model.event.EventDetail[String]]
 required: shapeless.LUBConstraint[shapeless.::[String,shapeless.HNil],edu.cornell.ansci.dairy.econ.model.event.EventDetail[_]]

The second part of the issue: is there any way to make this polymorphic over the size of detailIn? Based on my other readings, I assume not, and I can think of no way to do it in Scala. The best I can do is to support for convenience a fixed number lengths for detailIn string sequences, and if that is exceeded, the user of the class must use HList directly.

1 Answers
Related