For example, consider a small file.
one
two
three
four
five
six
seven
eight
nine
I would like to write code that would take a line iterator it: Iterator[String]
and make an iterator sectionIt: Iterator[Seq[String]]
that iterates over the sections.
In C# and Ruby this is easily accomplished with the yield keyword. There's talk of how to add that keyword to scala, but it depends on compiler plugins.
One way to create sectionIt
would be to create an Iterator[Seq[String]]
directly and override next
and hasNext
. This approach seems tedious and state-intensive for a higher-level language like Scala.
I realize there are other abstractions for streaming data, such as Iteratees, which may make this easier, but that's not an easy sell to someone who is learning a new language.
What is a good approach to writing the above code in Scala?