I have a trait, say:
sealed trait foo
And a case class that extends trait:
case class bar(data: List[String]) extends foo
I would like to write a function that accesses bar's data, but it is passed as foo, say:
def doSomething(x: foo) = {does something with foo.data}
And called like this:
val aBar = bar(some list)
doSomething(aBar)
But I can't access when the function doSomething expects a type foo. How can I get around this to access a bar type's values?
data
in Foo or do pattern matching if the trait is sealed. Or maybe ask for a Bar instead, – Luis Miguel Mejía Suárez