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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -