Shapeless: restricting case class types

心已入冬 提交于 2020-01-05 01:37:14

问题


(NOTE: split from Shapeless: Trying to restrict HList elements by their type and Shapeless: own HList constraint using Coproduct )

Question 3 - restrict case classes by parameter types

A very nice additional gain would be, if I could use HList constraints to constrain case class only to be built from AnyVals, Strings, and a specific MyBaseTrait, that recursively fulfill the same constraint. The constraint being defined on the base trait and not to have to touch any derived case class would be great. Something like:

trait MyBaseTrait
type MyCP = Boolean :+: Long :+: ... :+: String :+: MyBaseTrait
case class ValidSimple(b: Boolean, s: String) extends MyBaseTrait
case class ValidNested(s: String, vs: ValidSimple) extends MyBaseTrait
case class NotOfBaseTrait(l: Long)

case class InvalidNested(s: String, vs: NotOfBaseTrait) extends MyBaseTrait // => compile error

This would allow to fail a lot earlier. Is this possible? via Generic#Repr or DeepHList?

来源:https://stackoverflow.com/questions/32788780/shapeless-restricting-case-class-types

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!