I can only seem to iterate over the result val once. Calling length iterates over it, and therefore calling result.next causes an exception.
val result = for ( regex(name) <- regex findAllIn output) yield name
println(result.length)
println(result.next)
The result is AFAIK an Iterator[String], so I’m not sure why I can only iterate on it once.
You can try calling something like
toVectoron it so it stores it in a persistent collection, then you can iterate over it as many times as you like.Iteratorwill only let you traverse over the contents once, hence if you want to traverse it more than one time then turn it into a collection. Given that you have anIterator[String], calling something like.toVectoron it will give you aVector[String].