Currently I have the following code:
case class Foo(text: String, tag: Tag) {...}
object Foo {
def doSomething(fooSeq: Seq[Foo]) = fooSeq.map(f => f.tag)
def doSomethingElse() = {...}
}
I would like to move the doSomething method into an abstract class/trait so I can parametrize the tag and reuse the code later. Ideally, I'd like to do something like this:
case class Foo(text: String, tag: Tag) {...}
object Foo extends TraitFoo[Tag] {
def doSomethingElse() = {...}
}
---------------in another file----------------
trait TraitFoo[T] = {
def doSomething(fooSeq: Seq[TraitFoo[T]]) = fooSeq.map(f => f.tag)
}
However, the compiler complains that it cannot recognize f.tag inside TraitFoo.
I considered using an abstract class, but that also causes issues, because my object Foo does not need a constructor. It only needs to access the fields in its companion class.