I would like to create the following trait:
trait IntSet[A] extends Traversable[A] { self: Product =>
def foreach[U](f: A => U): Unit
}
case class AProduct(a: List[Int], b: List[Int]) extends IntSet[Int] {
def foreach[U](f: Int => U): Unit = {
for(aa <- a; bb <- b) f(aa*bb)
}
}
AProduct(List(1, 5,6,7), List(2,3,4,5)).toString
returns
(2, 3, 4, 5, 10, 15, 20, 25, 12, 18, 24, 30, 14, 21, 28, 35)
But I don't want the toString method from the case class to be overriden by the one of the traversable! How do I overcome that?
I want the final output to be:
"AProduct(List(1, 5,6,7), List(2,3,4,5))"
and if possible I would like to do something else than the following in IntSet:
override def toString = this.getClass().getName()+"("+self.productIterator.mkString(",")+")"
which works but I really would like not to reinvent the wheel.