abstract class ParsingState
case class First extends ParsingState
case class Second extends ParsingState
case class Third extends ParsingState
case class Command(first:String, second:String, third:String) 

def read( = { 
def helper(c:Command) = { 
  val p:ParsingState = //read heading, perform custom logic to assign the correct case class
  val newStrings:String = //read strings after heading, until we hit a new heading, need to return if EOF is hit
  p match { 
    case First => helper(Command(c.first + newStrings,c.second,c.third))
    case Second => helper(Command(c.first,c.second + newStrings, c.third))
    case Third => helper(Command(c.first,c.second,c.third + newStrings))


I did not run this through the scalac, I am coding this inside of the Stackoverflow textbox. I encourage other people to crib this code and make it better as a solution, as it is incomplete and I do not have access to a Scala compiler right now. This is solution has a functional paradigm in mind though.

Related Query

More Query from same tag