Iwan Roberts
Iwan Roberts

Reputation: 40

Define a generic trait with a function that returns a collection of types

I'm trying to create a Scala trait that is used as the base trait for a number of parsers. I have a number of case classes that will store the parsed datasets. All of these case classes extend the Parseable trait.

Some of the classes will return

Array[C <: Parseable]

others

Dataset[C <: Parseable]

How do I define the Parser trait so that the parse() function returns either of the above data structures?

Upvotes: 0

Views: 403

Answers (1)

Edmondo
Edmondo

Reputation: 20090

trait Parser[A[_], B <: Parseable]{

      def parse(s:String): A[B]

}

Upvotes: 1

Related Questions