New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Case classes should inherit from ProductN #1799
Comments
Imported From: https://issues.scala-lang.org/browse/SI-1799?orig=1 |
@paulp said: |
@DRMacIver said: case class Foo(foo : String, bar : Int);
case class Baz(baz : Int, bloop : String) extends Foo(bloop, baz); This would have to extend both Product2[String, Int] and Product2[Int, String], which isn't allowed. |
Rafael de F. Ferreira (rafaeldff) said: Anyway, for my use case I just wanted to have the arity of the case class encoded in the type system. I don't need to know the actual types of the arguments. I was hoping to do something like: abstract class Arity
abstract class N1 extends Arity
abstract class N2 extends Arity
abstract class N3 extends Arity
//...
class FiniteProduct[A <% Arity](val p:Product)
implicit def productArity1(p:Product1[_]) = new FiniteProduct[N1](p)
implicit def productArity2(p:Product2[_,_]) = new FiniteProduct[N2](p)
implicit def productArity3(p:Product3[_,_,_]) = new FiniteProduct[N3](p)
//...
//Note that the implicit defs above forget the argument types
def table[P <% FiniteProduct[_]](rows:List[P]) = Do something knowing that all products in rows have the same arity Should I take this to the mailing lists or open another ticket (or forget about this kind of guarantee and sulk)? |
@DRMacIver said: One thing I've found useful for dealing with case classes with specific sizes is to parameterise by their unapply methods: The companion object has a generated unapply method which returns an Option[ProductN[T1, ..., TN]]. |
@SethTisue said: |
Commit Message Bot (anonymous) said: scala> case class Bippy(x: Int, y: Int) scala> Bippy(5, 10).productIterator There is an even better idea available than lubbing the case class field Review by oderksy. |
Commit Message Bot (anonymous) said:
|
@paulp said: |
@adriaanm said: |
@ijuma said: |
@gkossakowski said: |
@Blaisorblade said:
|
@paulp said: |
Currently, only TupleN classes inherit from ProductN.
Case classes should also inherit from ProductN, where N is the value of the productArity of the case class.
The text was updated successfully, but these errors were encountered: