types - How to fix constraint on a collection of case class in Scala -
is there way have constraint on collection of case class. in case, want ensure elements in collection have same value first property.
here sample of code express mean
case class in[t](values : set[t]) trait case object a1 extends case object a2 extends case class element(k: a, v: string) in(set(element(a1, "xxx"), element(a1, "xxx"))) // should compile in(set(element(a1, "xxx"), element(a2, "xxx"))) // should not compile
is acceptable solution you?
case class in[t](values : set[t]) trait case object a1 extends case object a2 extends case class element[t <: a](k: t, v: string) in(set[element[a1.type]](element(a1, "xxx"), element(a1, "xxx"))) // should compile in(set[element[a1.type]](element(a1, "xxx"), element(a2, "xxx"))) // should not compile
Comments
Post a Comment